Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
Contributor III

Function to Reverse String / text

Hi

I am getting revered string from my system. For Example Item ABCD is loaded as DCBA.

Is there a function I can use to reverse the string, in the script itself?

Here is the script:

LIB CONNECT TO 'Sandra-Lavi (lavi_sandra)';

Parts:

LOAD

    Text(PARTNAME) as Parts.PARTNAME ;

SQL SELECT

PARTNAME,

....

FROM lavi.dbo.PART;

Thanks !!

Sandra

1 Solution

Accepted Solutions
Highlighted
Champion
Champion

Re: Function to Reverse String / text

try this:

LIB CONNECT TO 'Sandra-Lavi (lavi_sandra)';

Parts:

LOAD Parts.PARTNAME, concat(Letter,'',-row) as Reversed Group by Parts.PARTNAME;

LOAD

Text(PARTNAME) as Parts.PARTNAME,

interno() as row,

mid(Text(PARTNAME),Iterno(),1) as Letter

While IterNo() <= len(MyText);

SQL SELECT

PARTNAME,

....

FROM lavi.dbo.PART;

View solution in original post

13 Replies
Highlighted
Partner
Partner

Re: Function to Reverse String / text

I think that better option is Reverse() function of your ODBC. Oracle, MS SQL and Mysql have this funcition.

In Qlik you will need a lot of code.

Highlighted
Champion
Champion

Re: Function to Reverse String / text

Hi,

read this:

Reverse string

Highlighted
Partner
Partner

Re: Function to Reverse String / text

Try :

Load

  MyText,

  Concat(Letter,'',-row) as Reversed

Group By MyText;

Load

  MyText,

  IterNo() as row,

  Mid(MyText,IterNo(),1) As Letter

Inline

[

MyText

  DCBA

] While IterNo() <= Len(MyText);

Result:

Capture.PNG

Highlighted

Re: Function to Reverse String / text

Something like this might work

Table:

LOAD F1,

Concat(F1_Temp, '', -SNo) as F1_New

Group By F1;

LOAD AutoNumber(IterNo(), F1) as SNo,

F1,

Mid(F1, IterNo(), 1) as F1_Temp

While IterNo() <= Len;

LOAD F1,

Len(F1) as Len;

LOAD * INLINE [

    F1

    ABCD

    KLMASL

];

Highlighted
Contributor III
Contributor III

Re: Function to Reverse String / text

thanks,

I tried applying this to my script but didn't succeed

could you help me apply this to my script?

Highlighted
Champion
Champion

Re: Function to Reverse String / text

of course, attach your script

Highlighted
Contributor III
Contributor III

Re: Function to Reverse String / text

Here is the script:

LIB CONNECT TO 'Sandra-Lavi (lavi_sandra)';

Parts:

LOAD

    Text(PARTNAME) as Parts.PARTNAME ;

SQL SELECT

PARTNAME,

....

FROM lavi.dbo.PART;

Highlighted
Champion
Champion

Re: Function to Reverse String / text

try this:

LIB CONNECT TO 'Sandra-Lavi (lavi_sandra)';

Parts:

LOAD Parts.PARTNAME, concat(Letter,'',-row) as Reversed Group by Parts.PARTNAME;

LOAD

Text(PARTNAME) as Parts.PARTNAME,

interno() as row,

mid(Text(PARTNAME),Iterno(),1) as Letter

While IterNo() <= len(MyText);

SQL SELECT

PARTNAME,

....

FROM lavi.dbo.PART;

View solution in original post

Highlighted
Contributor III
Contributor III

Re: Function to Reverse String / text

thanks!

I assume you meant to put "PARTNAME" instead of MyText, right?

This is my script now.

and it still bring the reversed text..

Is there something wring with this ?

LIB CONNECT TO 'Sandra-Lavi (lavi_sandra)';


Parts:

LOAD Parts.PARTNAME, concat(Letter,'',-row) as Reversed Group by Parts.PARTNAME;

LOAD

Text(PARTNAME) as Parts.PARTNAME,

iterno() as row,

mid(Text(PARTNAME),Iterno(),1) as Letter

While IterNo() <= len(Text(PARTNAME));


SQL SELECT

PARTNAME

FROM lavi.dbo.PART;


load Text(PARTNAME), iterno() as row, mid(Text(PARTNAME),IterNo(),1) As Letter;


exit Script;