Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Omkar13
Contributor III
Contributor III

How to break string into multiple lines

Hi Qlik Experts,

I have a string field which I want to display in a report. The problem: the string isn't preformatted and look something like below-

Actual output:

-Lorem Ipsum is simply dummy text of the printing and typesetting industry. -Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. -It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. -It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Q. How do I break the string and add a line new line after every occurance of '-' ?

Desired output:

-Lorem Ipsum is simply dummy text of the printing and typesetting industry.
-Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
-It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
-It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

3 Solutions

Accepted Solutions
PrashantSangle

Hi,

 

Use subfield(),

try like

Load 

subfield(fieldname,'-') as fieldName

from tableName;

 

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

View solution in original post

Ksrinivasan
Specialist
Specialist

hi,

you can try subfield function

subfield(YourFieldname(messagefield), '-', 1) as FirstSentense,

subfield(YourFieldname(messagefield), '-', 2) as SecondSentense,

subfield(YourFieldname(messagefield), '-', 3) as ThirdSentense,

subfield(YourFieldname(messagefield), '-', 4) as ForthSentense,

subfield(YourFieldname(messagefield), '-', 5) as FifthSentense,

subfield(YourFieldname(messagefield), '-', 6) as SixthSentense,

and DO cross table function, you will get all  Sentences will come under sequence as your expected result,

ksrini

 

View solution in original post

QFabian
Specialist III
Specialist III

Hi @Omkar13 , you can try this, in script or in a expression :

expression :

replace(YourField, '-', chr(13))

 

script :

replace(YourField, '-', chr(13)) as Text

QFabian

View solution in original post

9 Replies
PrashantSangle

Hi,

 

Use subfield(),

try like

Load 

subfield(fieldname,'-') as fieldName

from tableName;

 

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Ksrinivasan
Specialist
Specialist

hi,

you can try subfield function

subfield(YourFieldname(messagefield), '-', 1) as FirstSentense,

subfield(YourFieldname(messagefield), '-', 2) as SecondSentense,

subfield(YourFieldname(messagefield), '-', 3) as ThirdSentense,

subfield(YourFieldname(messagefield), '-', 4) as ForthSentense,

subfield(YourFieldname(messagefield), '-', 5) as FifthSentense,

subfield(YourFieldname(messagefield), '-', 6) as SixthSentense,

and DO cross table function, you will get all  Sentences will come under sequence as your expected result,

ksrini

 

Omkar13
Contributor III
Contributor III
Author

Thanks  @PrashantSangle  @Ksrinivasan  I m a complete beginner at QLik Sense. Can you tell me how to apply the subfield and where? or Point me to correct direction. I will explore how to apply subfield on the internet

PrashantSangle

can you share sample data with expected output. Your requirement is not giving full idea about your issue

subfield() work in both script as well as in front end level.

 

Regards,

 

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Saravanan_Desingh

Try this,

tab1:
LOAD '-'&SubField(Str,'-') As Line;
LOAD * INLINE [
    Str
    "-Lorem Ipsum is simply dummy text of the printing and typesetting industry. -Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. -It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. -It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
];
Saravanan_Desingh

Output:

commQV22.PNG

QFabian
Specialist III
Specialist III

Hi @Omkar13 , you can try this, in script or in a expression :

expression :

replace(YourField, '-', chr(13))

 

script :

replace(YourField, '-', chr(13)) as Text

QFabian
Omkar13
Contributor III
Contributor III
Author

Thanks @QFabian that did the trick.😁  I believe using subfield is also a great option when it comes to breaking down large string value but in my case replace(YourField, '-', chr(13)) is a more appropriate solution as I want to show the value in a single text field.
Thanks @PrashantSangle @Ksrinivasan  your recommended solution also applies on my query and provides me more ways to manipulate larger string values.

QFabian
Specialist III
Specialist III

Excelent @Omkar13 , but You have to consider that subfield with 2 parameters  is going to create more rows, so that can change results in possible counts formulas.

QFabian