Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Learn how to migrate to Qlik Cloud Analytics™: On-Demand Briefing!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

I want to split a string into 35 charcters.


Hi,

           It;s urgent.I tried a lot but i didnt get it:

a string has many charcters :

1st 35 charcters into one field but should complete a word  .

ex:  the premium life insurance corporate company   which has a filed name  NM

it comes:

left(NM,35)

result:

the premium life insurance corporat           into NM1

e company                                                   into NM2

but  i want

the premium life insurance                             into NM1

corporate company                                          into  NM2

pls help.Thanks in advance

24 Replies
Qrishna
Master
Master

Ofcourse you can.

But as i said earlier i need to see some sample data.

paste some 10-15 records here.

Not applicable
Author

sunindia  Yeah  it is working  for almost ....still I am checking if any exceptions

Thank you

very much

sunny_talwar

Cool, once it works in the back end try these expressions:

Expression 1:

If(Len(Field) <= 35, Field, Left(Field, (Index(Left(Field, 36), ' ', -1))))


Expression 2:

If(Len(Field) <= 35, '', Right(Field, (Len(Field) - (Index(Left(Field, 35), ' ', -1)))))

Anonymous
Not applicable
Author

Another version:

NM1 = left(vText, 35 +  index(mid(vText, 36),' '))

NM2 = mid(vText, 35 +  index(mid(vText,36),' '))

(Where vText is a variable where I kept the text for testing - replace with your field name)

sunny_talwar

I think Michael‌ the problem with 35 + is that it will include the half word in NM1, whereas he wanted half word to go in NM2. I was trying this out first, but when I saw that he want the NM1 to be less than 35 completed words I had to take the longer route to get the solution. But I am sure there might be an easier way to get what he is looking for. Let me know what you think?

Best,

Sunny

Anonymous
Not applicable
Author

Maybe this:

=left(vText, index(left(vText,35), ' ',-1))

=mid(vText, index(left(vText,35), ' ',-1)+1)

The

index(left(vText,35), ' ',-1)

returns position of the last space in the first 35 characters.  After that we just need left() and mid() to cut out the pieces...

anyway sunindia, not much different from your solution

sunny_talwar

The problem then is that if I have a phrase like: I like sunny (which is 12 character long) it shows I like as NM1 and sunny as NM2 because then index(left(vText,35), ' ',-1) finds space before sunny to divide it.

Anonymous
Not applicable
Author

This one is a small problem - and you have the if() for that already.

Not applicable
Author

Guys , right now my server is down . I am waiting

Will update once I tried with others too . It's very

Confidential data I can't post any . I Apolozise .

Thanks & Regards

sunny_talwar

Hahahaha, that makes perfect sense Michael

Best,

Sunny