Message Boards Message Boards

1
|
14196 Views
|
3 Replies
|
10 Total Likes
View groups...
Share
Share this post:

Quotation marks in a string

Posted 12 years ago
How can I make string processing functions disregard quotation marks in a string? My program will automatically recieve and process student essays which will contain quotes.
POSTED BY: Jesse Friedman
3 Replies
There are two types of quotation marks you can get when importing text: those which Mathematica uses to form strings and other non-standard which cannot be used for that purpose. Both, when being inside the text, will parse correctly during import and will cause no trouble to your strings in general. Here is an example of standard quotation marks:
text1 = StringTake[Import["http://en.wikipedia.org/wiki/Albert_Einstein"], {2012, 2123}]

If you copy the output and paste in notebook you will see the imported string structure – it has backwards slash preceding the quotation mark to insure that there will be no string splitting on that mark:

You can do your string processing in a usual way being aware of these structures. If you still intend to get rid of them, the following will do:
StringReplace[text1, "\"" -> " ~QUOTE~ "]

Here is an example of none-standard quotation marks:
text2 = StringTake[Import["http://www.goodreads.com/quotes"], {520, 590}]

Again if you copy the output and paste in notebook you will see the imported string structure – these quotation marks cannot split/from a string, so they do not need backwards slash. So once again you can do your string processing in a usual way being aware of these structures. If you still intend to get rid of them, same trick will work:
StringReplace[text2, {"\[OpenCurlyDoubleQuote]" -> " ~OPEN QUOTE~ ", "\[CloseCurlyDoubleQuote]" -> " ~CLOSE QUOTE~ " }]

You can also replace them with space " " or empty string "". For more take a look at StringCases and RegularExpression.
POSTED BY: Vitaliy Kaurov
It's good to know that it will cause Import no trouble in production, but in my testing I was just defining a variable as a string, i.e.
 Is there any fix for that?
POSTED BY: Jesse Friedman
If you plan to process student essays then you need to import their text. Then variables need to have form as they appear in the essays (imported text). Then based on two examples above (depending on specific form of quotation marks of your essays) you could define:
text1 = "The quick brown fox jumped over the \"lazy\" dog"
or another possibility
text1 = "The quick brown fox jumped over the “lazy” dog"
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