Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
OmarBenSalem

Compare 2 strings

Hi all,

I have a simple question and hope I'll find someone willing to help  (@sunny_talwar )

I have 2 strings (no matter how they were constructed)

1) 45464748

2)454748

These strings are the concatenation of weeks; as u can see, the week 46 is missing in the second string.

I want to find a way to highlight this:

 

I tried using purgchar, purgechar(1,2) : but this returns 6 while I want to return 46 ...

Any idea?

Any help is much appreciated Heart

1 Solution

Accepted Solutions
OmarBenSalem
Author

Thanks Marcus,

 

I found out a way to do it when there ONE missing week:

 

if(len('45|46|47|48')=len('45|46|48'),'All weeks were imported', 'Week not imported : '&
SubField(
textBetween(
'45|46|47|48','|' , PurgeChar('45|46|47|48' , '45|46|48')) ,'|',-1)
&
PurgeChar('45|46|47|48' , '45|46|48')
)

 

result:Capture.PNG

 

 

View solution in original post

9 Replies
OmarBenSalem
Author

Ps: the solution must be in the front end and not in the script.
sunny_talwar

This is an example where you have 45464748 week... what happens for 2,3, 4, 5 weeks... do they look like 02030405 or do they look like 2345?
marcus_sommer

I doubt that there could be an easy and elegant solution within the UI especially if the strings could be really arbitrary and there might be also multiple missing parts. Therefore I think you would need multiple if-loop's for it ... You may start with something like:

if(len(S1) <> len(S2),
   if(mid(S1, 1, 1) <> mid(S2, 1, 1),
   ....

I think there could be a quite ugly solution be constructed ... What speaks against a script-solution preverable without these string-stuff or at least with some adjustments, for example with a zero white-space as delimiter and similar measures.

- Marcus

OmarBenSalem
Author

Thanks Marcus,

 

I found out a way to do it when there ONE missing week:

 

if(len('45|46|47|48')=len('45|46|48'),'All weeks were imported', 'Week not imported : '&
SubField(
textBetween(
'45|46|47|48','|' , PurgeChar('45|46|47|48' , '45|46|48')) ,'|',-1)
&
PurgeChar('45|46|47|48' , '45|46|48')
)

 

result:Capture.PNG

 

 

OmarBenSalem
Author

But if there were 2 weeks, example 46 and 47, this will return : 67...
sunny_talwar

I am confused as to how you are able to manipulate the data from 45464748 to 45|46|47|48?
OmarBenSalem
Author

I seperate weeks by '|'

See, this solution works if there ONE missing week:
if(len('1|2|3|4')=len('1|2|4'),'All weeks were imported', 'Week not imported : '&
SubField(
textBetween(
'41|2|3|4','|' , PurgeChar('1|2|3|4' , '1|2|4')) ,'|',-1)
&
PurgeChar('41|2|3|4' , '1|2|4')
)


OmarBenSalem
Author

It's just an example;

In reality, the string one is constructed as follow:
Concat(distinct SemainePanier,'|')

the string 2 :
if(PurgeChar( Capitalize(WeekDay(ReloadTime())),'.')='Lun', week(ReloadTime())-5&week(ReloadTime())-4&week(ReloadTime())-3&week(ReloadTime())-2,
(week(ReloadTime())-4)&'|'&(week(ReloadTime())-3)&'|'&(week(ReloadTime())-2)&'-'&(week(ReloadTime())-1))

Thus, I could add a seperator (in this case the | between weeks)
marcus_sommer

By several missing values an approach like the following might be useful:

purgechar(purgechar(purgechar(S2, subfield(S1, '|', 1) & '|'), subfield(S1, '|', 2) & '|'), ….

But like mentioned a script-solution might be more suitable maybe something like:

load * inline [
Week
45
46
48
];

load distinct ReloadWeek as MissingWeek where not exists(Week, ReloadWeek);
load week(today() - 35 + recno()) as ReloadWeek autogenerate 28;

- Marcus