Skip to main content
Announcements
Qlik Acquires Upsolver to Advance Iceberg Solutions: READ MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
michal10pl
Contributor
Contributor

Split string with every second same char

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.

Labels (1)
1 Solution

Accepted Solutions
tresesco
MVP
MVP

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;

Capture.PNG

However, there could be a simpler solution. This would give an idea for you and you can try to optimize it.

View solution in original post

2 Replies
tresesco
MVP
MVP

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;

Capture.PNG

However, there could be a simpler solution. This would give an idea for you and you can try to optimize it.

michal10pl
Contributor
Contributor
Author

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  "~".