Message Boards Message Boards

1
|
3787 Views
|
2 Replies
|
5 Total Likes
View groups...
Share
Share this post:
GROUPS:

Segmenting and extracting data from a string

Posted 12 years ago
I have a long dictionary-like string that I want to segment and store. It is in the format:
WORDA (n.)
Definition.
WORDB (n.)
Definition.
I want to store the data in a list of the form:
{{"WORDA","n.","Definition."},{"WORDB","n.","Definition."}}
Is there any (simple) way to do this WITHOUT using regular expressions?

-Jesse
POSTED BY: Jesse Friedman
2 Replies
s="
WORDA (n.)
Definition.
WORDB (n.)
Definition.
";
Partition[#,3]&@Flatten[Import[StringToStream@s,"Lines"]/.w_String:>StringSplit[w]]
POSTED BY: Rolf Mertig
I think showing a working reasonably sized actual string (just a few word defenitions) would help to figure this out. I guess your "Definition" is quite a few words and the whole string is quotation marks or stored in a file originally?
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract