Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

marcel_olmo
Valued Contributor

How to split a string like subfield

Hey guys!

I have a table like this :

Main FieldSecondary Field
1qwertyuiopasdfghjklñzxcvbnm
2mnbvcxzñlkjhgfdsapoiuytrewqopsasasasa

And I want to split the secondary field in parts of 7 chars.

I thought to use "subfield", but I need a char to reference the split, and I don't know how to insert a "diferential" chart every seven chars.

My result would be :

Main FieldThird Field
1qwertyu
1iopasdf
1ghjklñz

How could I do this?

Many thanks in advance.

Regards

Tags (3)
1 Solution

Accepted Solutions

Re: How to split a string like subfield

Hi

Try like this also,

Table1:

Load * Inline

[

MF,SF

1,qwertyuiopasdfghjklñzxcvbnm

2, mnbvcxzñlkjhgfdsapoiuytrewqopsasasasa

];

Let vLen =0;

For j= 0 to NoOfRows('Table1')-1

  vLen  = 0;

  Let vField1= Peek('SF',$(j),'Table1');

  Let vField2 = Peek('MF',$(j),'Table1');

  For i=0 to len(vField1)

  if mod($(i),7) = 0  then

  Load  Mid('$(vField1)', $(vLen)*7+1, 7) as SF1, $(vField2 ) as MF AutoGenerate 1;

  vLen = $(vLen)+1;

  End if

  NEXT

NEXT

But cleveranjos is an optimized way. This is also one way

4 Replies
Employee
Employee

Re: How to split a string like subfield

This code below does what you want

Table:

LOAD * INLINE [

    F1, F2

    1, qwertyuiopasdfghjklñzxcvbnm

    2, mnbvcxzñlkjhgfdsapoiuytrewqopsasasasa

];

LOAD

  F1 as [Main Field],

  F2 as [Secondary Field],

    IterNo() as i,

  Mid(F2,(IterNo()-1) * 7+1, 7) as [Third Field]

Resident Table

While IterNo() <= div(len(F2),7)+1;

Re: How to split a string like subfield

Hi

Try like this also,

Table1:

Load * Inline

[

MF,SF

1,qwertyuiopasdfghjklñzxcvbnm

2, mnbvcxzñlkjhgfdsapoiuytrewqopsasasasa

];

Let vLen =0;

For j= 0 to NoOfRows('Table1')-1

  vLen  = 0;

  Let vField1= Peek('SF',$(j),'Table1');

  Let vField2 = Peek('MF',$(j),'Table1');

  For i=0 to len(vField1)

  if mod($(i),7) = 0  then

  Load  Mid('$(vField1)', $(vLen)*7+1, 7) as SF1, $(vField2 ) as MF AutoGenerate 1;

  vLen = $(vLen)+1;

  End if

  NEXT

NEXT

But cleveranjos is an optimized way. This is also one way

mov
Esteemed Contributor III

Re: How to split a string like subfield

Clever Anjos , Mayil Vahanan Ramasamy,

Your both solutions are fine.  I'm just adding one more

Source:
LOAD * INLINE [
Main, Second
1,  qwertyuiopasdfghjklñzxcvbnm
2,   mnbvcxzñlkjhgfdsapoiuytrewqopsasasasa ];

FOR n=0 TO 100  // the "limit" is hardcoded here, but can be pre-calculated in a variable
Result:
LOAD
  Main,
  mid(Second, $(n)*7+1, 7) as Third
RESIDENT Source
WHERE len(mid(Second, $(n)*7+1, 7))>0;
NEXT

Regards,

Michael

marcel_olmo
Valued Contributor

Re: How to split a string like subfield

Thanks Guys! It works like a charm! The 3 solutions did what I need.

Regards, Marcel.