Message Boards Message Boards

Find and replace carriage returns in data set

Posted 9 years ago

Hi all,

I'm working with a very simple two-column data set, and one of the columns has large text strings. Within the strings are carriage returns that I'd like to remove. Current versions of Excel and Numbers (from where the data comes) do not recognize carriage returns, and so I'm trying to remove the carriage returns in Mathematica to then perform some natural language processing analyses on.

Can someone show me how to remove carriage returns from a particular column of data?

Many thanks,

Peter

POSTED BY: Peter Nilsson
2 Replies

Hi Peter,

it would be very useful to have an example dataset. It is difficult for me to reproduce the problem.

Cheers,

Marco

POSTED BY: Marco Thiel

A carriage return is often found (with XLS) als the character \n (sometimes txt files have \r) When you import the test.xls with

data=Flatten[ Import["test.xls"],1]
data//Grid

enter image description here

Now if you want the second column that contains text with some \n characters you can select the row and delete all the carriage returns with

Map[StringReplace[#, "\n" -> ""] &, data[[All, 2]]]

{row 1And here is some text.And some more,row 2And here is some text.And some more,row 3And here is some text.And some more,row 4And here is some text.And some more,row 5And here is some text.And some more,row 6And here is some text.And some more}

Hope this helps.

Attachments:
POSTED BY: l van Veen
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