Taras
asked on
Memo field string need to split
In Crystal Report XI R2 I have a memo filed that has text in.
I need to split this text in two fields. For this I was thinking about creating two formulas.
Usually in the middle of text there is Chr(13) and Chr(10). It looks easy to solve this, just use InStr to find its position and then use left or right function to pull out first part of text then second part.
However or but.
Problem is that user entering text sometimes put two times Chr(13),Chr(10),Chr(13),Ch r(10) in the middle of text.
Sometimes he is putting chr(160) in too and it looks …..Chr(13),Chr(10),Chr(160 ),Chr(13), Chr(10)…
Sometimes user start text with Chr(13),Chr(10) or Chr(160) or he first enters tab Chr(9) then start to enter text.
I need to remove all from left side(beginning of text e.g.Chr(13),Chr(10),Chr(9) ,Chr(160)) .
I need text starts with capitalizing first letter of text. I need to find first occurrence of Chr(13),Chr(10) then extract text before that .
Then in need to remove eventually Chr(13),Chr(10) or Chr(160) or Chr(9) from beginning of second part of text .For the second part of text I have to cut everything after end of text as user could put Chr(13),Chr(10),Chr(9) or Chr(160) there too.That second part of text has to go to second formula.
I need to split this text in two fields. For this I was thinking about creating two formulas.
Usually in the middle of text there is Chr(13) and Chr(10). It looks easy to solve this, just use InStr to find its position and then use left or right function to pull out first part of text then second part.
However or but.
Problem is that user entering text sometimes put two times Chr(13),Chr(10),Chr(13),Ch
Sometimes he is putting chr(160) in too and it looks …..Chr(13),Chr(10),Chr(160
Sometimes user start text with Chr(13),Chr(10) or Chr(160) or he first enters tab Chr(9) then start to enter text.
I need to remove all from left side(beginning of text e.g.Chr(13),Chr(10),Chr(9)
I need text starts with capitalizing first letter of text. I need to find first occurrence of Chr(13),Chr(10) then extract text before that .
Then in need to remove eventually Chr(13),Chr(10) or Chr(160) or Chr(9) from beginning of second part of text .For the second part of text I have to cut everything after end of text as user could put Chr(13),Chr(10),Chr(9) or Chr(160) there too.That second part of text has to go to second formula.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mlmcc
I got this error In formula testx
Global StringVar Array strArray;
StringVar strTest;
strTest := Replace(strTest,chr(160),' ');
strTest := Replace(strTest,chr(9),'') ;
strArray := Split(strTest,chr(13)+chr( 10));
strArray[1];----- A subscript must be between 1 and the size of the array.
I got this error In formula testx
Global StringVar Array strArray;
StringVar strTest;
strTest := Replace(strTest,chr(160),'
strTest := Replace(strTest,chr(9),'')
strArray := Split(strTest,chr(13)+chr(
strArray[1];----- A subscript must be between 1 and the size of the array.
You'll get that error if the field is empty. Try replacing the last line with this:
if chr(13)+chr(10) in strTest then
strArray[1]
James
if chr(13)+chr(10) in strTest then
strArray[1]
James
ASKER
I made mistake I did not replace strTest with my table field.
It removed error : A subscript must be.....
Do I still need to put this suggestion as James said?
It removed error : A subscript must be.....
Do I still need to put this suggestion as James said?
You would only need a check like that if the field could be completely empty (not even a space). If the field will never be empty, you shouldn't need that test, but I don't think there would be any harm in including it anyway, just to play it safe.
James
James
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You'll also get an error if the string is empty (not null). For example, the following will give you an error:
Split ("", ",") [ 1 ]
James
Split ("", ",") [ 1 ]
James
ASKER
Thanks a lot
To get the first string
Create a formula - Testx
Open in new window
To get other strings (second string)
Open in new window
Third String (if there are multiple chr(13) + chr(10))Open in new window
Just add as many as necessary
mlmcc