Hi Experts,
I need to split the Strings,but i don’t no whether this is possible…as i tried for all String functions…[:(]
E.g. String = Dear “Name” Your balance is “Balance”
I need the result as:
String1 = Dear
String2 = “Name”
String3 = Your
String4 = balance
String5 = is
String6 = “Balance”
Can anyone tried of this…or help me…
Thanks,
VKunj
kash387
September 15, 2010, 11:40am
2
Hi VKunj,
welcome to DUG…!!!
You can use string functions…
Find the space and copy the string… save it to STRING 1 and also Delete STRING1 from the Original String
Repeat the same thing till you get the last word of your string…!!!
DRB
September 15, 2010, 11:48am
3
Hi,
In addition to what Kashyap said, you can use STRPOS for finding out substring:
Position := STRPOS(String, SubString)
And then COPYSTR and DELCHR for copying and then deletion of sub-string.
Vkunj
September 16, 2010, 7:50am
4
Hi Kashyap,
Thanks for your reply.
But i cannot take the space alone, as for E.g if i have a word say “Balance (LCY)” field, in this case i want the full word.
Actually the line will be looking like this…
E.g: Dear “Customer” the balance is “Balance (LCY)”
So the total splitted string should be 6 and not 7… “Balance (LCY)” is a 1 word.
Thanks,
Aswini
kash387
September 16, 2010, 8:26am
5
But i cannot take the space alone, as for E.g if i have a word say “Balance (LCY)” field, in this case i want the full word.
Actually the line will be looking like this…
E.g: Dear “Customer” the balance is “Balance (LCY)”
Hi Aswini,
Is your line have fixed format…??? i mean “(LCY)” will be there just after Balance.???
In this case, Either you can fix it (I dont suggest this ever…) or if these are the last words of your sentence then you can combine them after splitting…!!!
Can you tell me why you want to split this way…???
Vkunj
September 16, 2010, 8:41am
6
Hi Kashyap,
The format will be like that… its not that LCY will be there… Double quotes will be there in the middle of a string as given in my example.
So i want the result as :
String 1 = Dear String 2 = “Customer” String 3 = the String 4 = balance String 5 = is String 6 = “Balance (LCY)”
Actually i want the value to be replaced in the string which is in with double quotes from a table… so i need to be splitted…
Any idea???
Thanks,
Aswini
kash387
September 16, 2010, 8:55am
7
The format will be like that… its not that LCY will be there… Double quotes will be there in the middle of a string as given in my example.
So i want the result as :
String 1 = Dear String 2 = “Customer” String 3 = the String 4 = balance String 5 = is String 6 = “Balance (LCY)”
Actually i want the value to be replaced in the string which is in with double quotes from a table… so i need to be splitted…
Aswini,
You have to use different string functions to fulfill the requirement…
As you have mentioned its having double quotes, then first collect those words by finding double quotes…
update the original string, and then collect rest of words finding space…
See, you have DB, you have Data, you have entries, you have requirements and you have scenairos…
So ultimately its you who have to decide how to use these functions to achieve this…
coz when you are working with strings, it can be tricky…!!!
If you have any doubt, you can ask again…!!!
Vkunj
September 16, 2010, 10:03am
8
Thanks Kashyap… But how to get the start and end of double quotes… from a single line…
kash387
September 16, 2010, 10:17am
9
[^o)]…
the easiest way is to replace those double quotes with comma… coz we have function SELECTSTR(position,commastring)
else again find position of first " then find position of second " and then copy that string…!!! (dont go for this if you can get result through comma string…!!!)
I have a small function for this:
Token(VAR Text : Text[1024];Separator : Text[1]) Token : Text[1024]
Pos := STRPOS(Text,Separator);
IF Pos > 0 THEN BEGIN
Token := COPYSTR(Text,1,Pos-1);
IF Pos+1 <= STRLEN(Text) THEN
Text := COPYSTR(Text,Pos+1)
ELSE
Text := '';
END ELSE BEGIN
Token := Text;
Text := '';
END;
This function can be used as follows:
String := 'Dear "Name" Your balance is "Balance"';
String1 := Token(String,' ');
String2 := Token(String,' ');
String3 := Token(String,' ');
...
Or simpler:
String := 'Dear "Name" Your balance is "Balance"';
WHILE STRLEN(String) > 0 DO BEGIN
i := i + 1;
String[ i ] := Token(String,' ');
END;
String := ‘Dear “Name” Your balance is “Balance”’;
Vkunj
September 16, 2010, 12:25pm
11
Hi Thomas,
Thanks, but my String can be
String := ‘Dear “Name” Your balance is “Balance (LCY)”’; So I cannot split by space alone, where the last string is a single word which will get broken.
i couldn’t get either with space or with special characters alone… [:(]
DenSter
September 16, 2010, 1:05pm
12
So now you know about the string functions. You now know how to find spaces, finding other characters works exactly the same. Use that knowledge to figure out an efficient way to program your requirement.
Vkunj
September 16, 2010, 1:23pm
13
Hi Kashyap,
Thanks…
Selectstr() works for option strings… so in this case it wont work…
And StrPos() in help - it is given as
// The STRPOS function is case-sensitive. Furthermore, it only // returns the position of the 1st occurrence of the substring.
i m trying it with all string functions…let me see…
Dear VKunj, in order to get qualified replies it would be very helpful in what context you need this. There has been lots of answers on how to split strings, and by extending this it can be done.
To me it sounds like you are trying to parse out some field names in a text string, so you can insert database values instead, is that correct?
Nothing will be broken because if no more spaces are found, the function will return the complete remaining string.
kash387
September 17, 2010, 4:29am
16
Selectstr() works for option strings… so in this case it wont work…
And StrPos() in help - it is given as
// The STRPOS function is case-sensitive. Furthermore, it only // returns the position of the 1st occurrence of the substring.
I have tried and tested with your string for myself development, and i got the 6 strings…
I cant give you that solution because you have to develop it but here is the hints…
Create a Text Variable STRING to store your original string…
other 6 text variables to split and store…
integer i to use in loop
pos an integer variable with dimension (based on how many double quotes can be there…)
use FOR loop with increasing i ,
store the position of double quotes in your pos[i] array…
then using delstr and pos[i] delete the double quotes,
then again use for loop to insert comma at the pos[i] (pos[i] indicates the position of double quotes]
Now your string has comma and you can use SELECTSTR …
Just make the codes based on my above description…
You will get that double quote phrases, but to split remaining parts you have to use STRPOS to find space and DELSTR and COPYSTR…
Okay…!!!
Vkunj
September 17, 2010, 4:49am
17
Dear SNielsen,
That is what is exactly needed… like i have to display the values in between the strings…which has Double Quotes(for identification)…
Thanks,
Aswini
Vkunj
September 17, 2010, 7:31am
18
Hi Guys… Thanks for all your replies… and i have got the solution using string functions…
Thanks…
Aswini
kash387
September 17, 2010, 7:35am
19
Hey Aswini,
Thats good that you get what you were looking for…!!!
Lamba
June 27, 2014, 12:45pm
20
Hi Thomas,
My String is X|Y|Z
The string is dynamic, i tried your common function by unfortunately , its picking up last value.
I wrote the function as:
Where Split : Text[1024], i used as return type.
SplitString(Text : Text[1024];Separator : Text[1]) Split : Text[1024]
Pos := STRPOS(ltxtroutingNo,Separator);
IF Pos > 0 THEN BEGIN
Split := COPYSTR(ltxtroutingNo,1,Pos-1);
IF Pos+1 <= STRLEN(ltxtroutingNo) THEN
Text := COPYSTR(ltxtroutingNo,Pos+1)
ELSE
Text := ‘’
END ELSE
Split := Text;
Text := ‘’;
Am i writing the function in wrong manner?