0

如果我有成千上万的字符串

Toshiba - Satellite C855D-S5100 笔记本电脑、AMD E 系列处理器 (1.3 GHZ)、4GB DDR3、320GB 硬盘、15.6 英寸显示屏、AMD Radeon HD 6310、双层 DVD±RW/CD-RW、802.11 b/g/n , Windows 8 » 百思买售价 279.99 美元

并有一个具有不同属性的笔记本电脑对象,例如:

  • 处理器
  • 内存
  • 硬盘
  • 操作系统
  • ETC

我想为每个字符串创建一个笔记本电脑对象,并使用字符串中的格式化数据设置属性。

我想知道是否有一种简单的方法可以做到这一点,而不是通过执行 s.split(",") 将字符串拆分为一个数组,循环遍历它并将其与关键字进行比较:

即如果字符串包含“DDR3”,则将该字符串设置为RAM属性

4

1 回答 1

0

Can you tell if for the thousands of strings you have some semblance of regularity, structure. The difficulty of what you ask is dependant of the variability between 2 different entries.

Toshiba - Satellite C855D-S5100 Laptop, AMD E-Series Processor (1.3 GHZ), 4GB DDR3, 320GB HDD, 15.6" Display, AMD Radeon HD 6310, Double-layer DVD±RW/CD-RW, 802.11 b/g/n, Windows 8 » for $279.99 at Best Buy

Is pretty disimilar from

Apple MacBook Pro - Core i5 2.5 GHz - 500 GB HDD / 5400 rpm - 13.3″ 1280 x 800 - 4 GB RAM - English

In one you have RAM in the other DDR3. In one you have 4GB with no space and in the other there is a space. But it's not hopeless if your list contains strings which are all very similar in structure. Then I'd say figure out a regex for what you want to extract.

于 2013-02-18T02:01:33.647 回答