Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Aditya_Chitale
Specialist
Specialist

Combining Multiple same consecutive characters into one

Hi All,

I have a requirement where I want to combine multiple same consecutive characters in a string into one.

Lets say for eg I have a string value as : ____1__2_abc_____hhv

I want to check if same character (in my case underscore) is appearing consecutively in a string and combine it into single character.

Final output should be like : _1_2_abc_hhv

Any help would be appreciated

 

Regards,

Aditya

Labels (5)
1 Solution

Accepted Solutions
brunobertels
Master
Master

Hi 

Try this 

 

temp:

Load SourceString,

SubField(SourceString, '_') as OneValue

Inline [

SourceString

" ____1__2_abc_____hhv"

" ______5__7_abc____lmn"

" ___9__8___def___ijk"

];

NewTable:

LOAD SourceString,

Concat(distinct OneValue, '_') as CleanString

Resident temp

Group by SourceString;

DROP Table temp;

brunobertels_0-1699002965855.png

 

 

View solution in original post

2 Replies
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

You can try a solution like this. Maybe there is a better solution

_map:
Mapping LOAD
  test,
  '_' as new
Inline [
  test
  ______
  _____
  ____
  __
];


LOAD
  test,
  MapSubString('_map', test) as test4
Inline [
  test
  ____1__2_abc_____hhv
  ____2__RT_sdfsdf____e
];

 

Help users find answers! Don't forget to mark a solution that worked for you!
brunobertels
Master
Master

Hi 

Try this 

 

temp:

Load SourceString,

SubField(SourceString, '_') as OneValue

Inline [

SourceString

" ____1__2_abc_____hhv"

" ______5__7_abc____lmn"

" ___9__8___def___ijk"

];

NewTable:

LOAD SourceString,

Concat(distinct OneValue, '_') as CleanString

Resident temp

Group by SourceString;

DROP Table temp;

brunobertels_0-1699002965855.png