how to find the new line character

HI to all
could u plz tell me how to find the new line character and it shoud replace with other character
suppose i have a list strings.i want to pass the input as a string .now it is a string.how to find the new line char with in the strings.how could i convert it into other char.
i used pub.string.replace service and passed the input string and in the substring parameter i have passed the and in the replace string i passed \ctrf char.but i am not getting output with what i want .could any one plz tell me what is the serivice to find the new line char and it should replace with \crlf char.

Thanks & Regrds

kishore

you can create a java service which generate the newline caractere :

IDataCursor pipelineCursor = pipeline.getCursor();
IDataUtil.put( pipelineCursor, “crlf”, “\r\n” );
pipelineCursor.destroy();

:wink:

OR
you can use the pub.string.replace service. In the replaceString >>>right click>>>Use large editor>>>hit enter. Thats your new line.

kerni

1 Like

Please be aware that end-of-line is indicated differently on different platforms. CRLF is not a “newline” character. It’s a character pair consisting of a carriage return (0x0d) and a linefeed (0x0a) that indicates end-of-line in Windows. Linefeed and newline are synonomous.

Windows: carriage return, linefeed (newline)
Unix: linefeed (newline)
Mac: carriage return

Either technique above will work IF the data you’re doing the search and replace on contains a CRLF pair. If the data you’re working with contains only CR or only LF then those techniques will not work.

Hi,
Does anyone have any tips for converting Unix linefeed character to Windows CRLF ???

Cheers,
David

I’ve been playing around with pub.string:replace and have discovered something funny.

If I specify “\x0a” for search string and then open larger editor for replace string and hit enter 2 or 3 times.

If source data only contains Unix Linefeed characters “0x0a”, then the replaced values are multiples of “0x0a”.

But, if source data contains at least one Windows CRLF (“0x0d”“0x0a”), then all Unix Linefeed characters are replaced with CRLF.

I’m using a hex editor to confirm the contents of the data both before and after and the results are consistent.

Has anyone else experienced this ??

Cheers,
David

Hi David,

If your intention is to convert a file from unix to windows format, thats not a right way to do it. I would prefer to execute a command ‘unix2dos’ which will convert efficiently parsing or replace after reading the file.

My 0.02$,
Niteesh

Thanks Kerni and guys
I had a similar requirement
had to load CSV file did the flat file dictionary and schema with no record identifier
But had to remove the header record from the string before loading it to flatfile.

Sample input

EmployeeId,EmployeeName,DOJ,City,Department CR LF
1234,QWERTY,12-08-2013,Banaglore,GHT CR LF
1235,PQRSTUV,12-08-2013,Banaglore,IMBT CR LF
1239,HOWAREU,19-08-2013,Banaglore,FGTH CR LF
1240,IMFINE,19-08-2013,Chennai,GCS CR LF
1236,HIHELLO,12-08-2013,Banaglore,QWER CR LF

Output
1234,QWERTY,12-08-2013,Banaglore,GHT CR LF
1235,PQRSTUV,12-08-2013,Banaglore,IMBT CR LF
1239,HOWAREU,19-08-2013,Banaglore,FGTH CR LF
1240,IMFINE,19-08-2013,Chennai,GCS CR LF
1236,HIHELLO,12-08-2013,Banaglore,QWER CR LF

would have been nice feature if we could drop records or skip records using the delimiter while loading the data into ffData using the pub.flat:convertToValues.
anyways all good, thanks

May be a feature request list to SAG :smiley:

HTH,
RMG

Has anyone found a way to handle removing newlines nicely?

I am trying to remove all newlines in some of my strings, using string.replace and hitting enter in large text editor, as bove. My results look good when displayed in the Results pane, with no new lines. However if I use Flow to save this to a file and open it (Linux) or if I just copy and paste from the Results into Notepad++ (Windows), I find that the newlines appear. Looking with a hex viewer, it appears that there are 0x0a characters present.

I have tried using another string.replace to search for “\x0a” but this seems to have no effect. Tried a bunch of other combinations with “\x0d0a”, “\x0d”, etc but had no luck so far.

Probably use System.getProperty(“line.separator”) to get line separator relative to environment before replace

2 Likes

Thanks! Worked perfectly.