Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Parse a text field without delimiters

I have field from a csv file that contains a series of letters and numbers.  The number of characters in this field varies.  It is always an even number of characters.  I need to parse this field into 2 characters.  Example is shown below.

Field contains this series of characters:  08102733364F4L4N4S51606487ACARCCFAFLFXP5SCT0.  I would like to parse this field into columns...

column1 08

column2 10

column3 27

column4 33

etc...

Final result would be the string above with length of 44, will be parsed into 22 columns.

Thank you in advance to anyone who can offer guidance.

1 Solution

Accepted Solutions
maximiliano_vel
Partner - Creator III
Partner - Creator III

Pls try this

Tmp:

LOAD '08102733364F4L4N4S51606487ACARCCFAFLFXP5SCT0' as Test

AutoGenerate 1;

Test:

LOAD Mid(Test, 1, 2) as Col

Resident Tmp;

Concatenate(Test)

LOAD Mid(Test, 2*IterNo()+1, 2) as Col

RESIDENT Tmp

While Mid(Test,2*IterNo()+1,1)<>'';

DROP Table Tmp;

STORE Test into Test.qvd;

DROP Table Test;

LOAD *

FROM [Test.qvd]

(qvd, filters(

Transpose()

));

View solution in original post

4 Replies
maximiliano_vel
Partner - Creator III
Partner - Creator III

Pls try this

Tmp:

LOAD '08102733364F4L4N4S51606487ACARCCFAFLFXP5SCT0' as Test

AutoGenerate 1;

Test:

LOAD Mid(Test, 1, 2) as Col

Resident Tmp;

Concatenate(Test)

LOAD Mid(Test, 2*IterNo()+1, 2) as Col

RESIDENT Tmp

While Mid(Test,2*IterNo()+1,1)<>'';

DROP Table Tmp;

STORE Test into Test.qvd;

DROP Table Test;

LOAD *

FROM [Test.qvd]

(qvd, filters(

Transpose()

));

svenkita
Creator II
Creator II

Hi Temieka Clay

I have done a example hope it helps

Following is the script

IATables:

LOAD * INLINE [

KEY,Text

KEY1,08102733364F4L4N4S51606487ACARCCFAFLFXP5SCT0

];

FOR nTabIdx=0 TO NoOfRows('IATables')-1

  Let vKey=peek( 'KEY',$(nTabIdx),'IATables');;

  Let vText=peek('Text',$(nTabIdx),'IATables');;

  Let vLen = Len(vText);

  For i = 1 to vLen step 2

   if i=1 then

   let vNewText =  Mid(vText,i,2);

   ELSE

   let vNewText = vNewText & ';' & Mid(vText,i,2);

   end if;

  next

   

  Left Join (IATables)

  LOAD * INLINE [

  KEY,NewText

  $(vKey),$(vNewText)

  ];

  Let vNewText="";

NEXT

NewTableWithColumn:

Load KEY,SubField(NewText,';') as NewColumn,RowNo(TOTAL) as ColumnIndex

Resident IATables;

Anonymous
Not applicable
Author

Thank you so much for responding @Maximiliano!  I copied your code into a blank file and it worked like a charm.  I am going to copy it into my actual file that contains the rest of the fields.  I will swap out the necessary fields and hope it works.  I will keep you posted.

Anonymous
Not applicable
Author

Thank you so much for responding Venkita!  Your solution also worked too.  I will add your code to my file and see what happens.