Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
hbuchetmann
New Contributor III

Split Text in a field without seperating words

Hello Qlikview-Community,

i am looking for a solution to the following problem:

Ich have a text field = Name in a table with up to 80 chars long.

I want to seperate it into two textfields Name1 and Name2, but without sperating words.

 

Example:

Namefield=This is a text which is much much much longer than 40 chars, but not longer than 80

LEFT(Namefield,40) AS Namefield1 = This is a text which is much much much l

RIGHT(Namefield,40) AS Namefield2 = onger than 40 chars, but not longer than 80

Is there a away to avoid seperating single words dynamically?

 

1 Solution

Accepted Solutions

Re: Split Text in a field without seperating words

Try this

Table:
LOAD *,
	 Index(Left(Namefield, 40), ' ', -1) as SpacePos,
	 Left(Namefield, Index(Left(Namefield, 40), ' ', -1)) as Namefield1,
	 Right(Namefield, Len(Namefield) - Index(Left(Namefield, 40), ' ', -1)) as Namefield2;
LOAD * INLINE [
    Namefield
    "This is a text which is much much much longer than 40 chars, but not longer than 80"
    "This is a text which is much much longer than 40 chars, but not longer than 80"
    "This is a text which is much longer than 40 chars, but not longer than 80"
];

View solution in original post

4 Replies

Re: Split Text in a field without seperating words

In this case, where would you want the longer to show up? First Half or Second half and why?? or does it not matter?

hbuchetmann
New Contributor III

Re: Split Text in a field without seperating words

The length of Namefield1 should not exceed 40 chars, so the longer should go completly to Namefield2

Re: Split Text in a field without seperating words

Try this

Table:
LOAD *,
	 Index(Left(Namefield, 40), ' ', -1) as SpacePos,
	 Left(Namefield, Index(Left(Namefield, 40), ' ', -1)) as Namefield1,
	 Right(Namefield, Len(Namefield) - Index(Left(Namefield, 40), ' ', -1)) as Namefield2;
LOAD * INLINE [
    Namefield
    "This is a text which is much much much longer than 40 chars, but not longer than 80"
    "This is a text which is much much longer than 40 chars, but not longer than 80"
    "This is a text which is much longer than 40 chars, but not longer than 80"
];

View solution in original post

hbuchetmann
New Contributor III

Re: Split Text in a field without seperating words

Thank you very much Sunny_talwar,

i just tired it out and it works like a charm!

 

Best wishes,

Hermann