Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I'm trying to cut long string on small parts, using to this every second separator. To show what i mean, i would like to show you an example:
This is my table:
A | ab1~1001~de2~4002~xy7~6009~...
B | er1~5889~ui2~3645~op7~4531~...
...
And i want to receive:
A | ab1~1001
A | de2~4002
A | xy7~6009
B | er1~5889
B | ui2~3645
...
I know that i should use functions like for, peek and subfield but can't stick this together to get a solution.
One could be like:
t1:
Load
SubField(String,'~') as tString,
RowNo() as RN,
String
;
Load * Inline [
String
A | ab1~1001~de2~4002~xy7~6009
B | er1~5889~ui2~3645~op7~4531];
Load
SubField(String, '|',1)& '| '&
Replace(NewString,SubField(String, '|',1)& '| ','') as NewString,
String;
Load
SubField(ttString, '##') as NewString,
String;
Load
Replace(Replace(
Concat( Distinct If(Mod(RN,2)=0, tString&'@@', tString), '~', RN)
, '@@~','##'), '@@','') as ttString,
String
Resident t1 Group By String;
Drop table t1;
However, there could be a simpler solution. This would give an idea for you and you can try to optimize it.
One could be like:
t1:
Load
SubField(String,'~') as tString,
RowNo() as RN,
String
;
Load * Inline [
String
A | ab1~1001~de2~4002~xy7~6009
B | er1~5889~ui2~3645~op7~4531];
Load
SubField(String, '|',1)& '| '&
Replace(NewString,SubField(String, '|',1)& '| ','') as NewString,
String;
Load
SubField(ttString, '##') as NewString,
String;
Load
Replace(Replace(
Concat( Distinct If(Mod(RN,2)=0, tString&'@@', tString), '~', RN)
, '@@~','##'), '@@','') as ttString,
String
Resident t1 Group By String;
Drop table t1;
However, there could be a simpler solution. This would give an idea for you and you can try to optimize it.
I used this char " | " to show another column in table. My table consist two columns. In the first one are chars like A, B C..., and in the second one are this long chars that need to be splited with every second "~".