Split comma separated values from Text component

Stimulsoft Reports.NET discussion
Post Reply
User avatar
dmasterplan
Posts: 143
Joined: Thu Mar 17, 2022 4:04 am
Location: Philippines

Split comma separated values from Text component

Post by dmasterplan »

I have Name-Company,Name-Company value in my Text Component and I want to split it (split comma separated).
and make it
1. Name-Company
2. Name-Company
How/where can I do it? in Databand Before Print event?
Last edited by dmasterplan on Thu Mar 31, 2022 9:18 am, edited 1 time in total.
Lech Kulikowski
Posts: 7338
Joined: Tue Mar 20, 2018 5:34 am

Re: Split comma separated values from Text component

Post by Lech Kulikowski »

Hello,

What do you need to do with these values after splitting?

Thank you.
User avatar
dmasterplan
Posts: 143
Joined: Thu Mar 17, 2022 4:04 am
Location: Philippines

Re: Split comma separated values from Text component

Post by dmasterplan »

Lech Kulikowski wrote: Thu Mar 31, 2022 8:30 am Hello,

What do you need to do with these values after splitting?

Thank you.
I want to display it again in the same component.
With the number before the text. e.g.
1. Name-Company
2. Name-Company
Great Thanks!
Lech Kulikowski
Posts: 7338
Joined: Tue Mar 20, 2018 5:34 am

Re: Split comma separated values from Text component

Post by Lech Kulikowski »

Hello,

You can use the following code in the BeforePrint event:

Code: Select all

var i = 1;
using (System.IO.StringReader sr = new System.IO.StringReader(Variable1.Replace(",","\n")))
{
	string line;
	while ((line = sr.ReadLine()) != null)
	{
    	Variable2 += i++.ToString() + ". " + line + "\n";
	}
}
or the following expression for split without numeration:
{Variable1.Replace(",","\n")}

Thank you.
Attachments
Zrzut ekranu 2022-03-31 151005.png
Zrzut ekranu 2022-03-31 151005.png (106.14 KiB) Viewed 1482 times
User avatar
dmasterplan
Posts: 143
Joined: Thu Mar 17, 2022 4:04 am
Location: Philippines

Re: Split comma separated values from Text component

Post by dmasterplan »

Lech Kulikowski wrote: Thu Mar 31, 2022 1:11 pm Hello,

You can use the following code in the BeforePrint event:

Code: Select all

var i = 1;
using (System.IO.StringReader sr = new System.IO.StringReader(Variable1.Replace(",","\n")))
{
	string line;
	while ((line = sr.ReadLine()) != null)
	{
    	Variable2 += i++.ToString() + ". " + line + "\n";
	}
}
or the following expression for split without numeration:
{Variable1.Replace(",","\n")}

Thank you.
This is my code. But I am not getting the correct output:

string Variable1 = dsPackages.Package_In_Charge;

var i = 1;
using (System.IO.StringReader sr = new System.IO.StringReader(Variable1.Replace(",","\n")))
{
string line;
while ((line = sr.ReadLine()) != null)
{
dsPackageInCharge.TextValue += i++.ToString() + ". " + line + "\n";
}
}

I have attached an image of the result.
Attachments
ss.png
ss.png (22.85 KiB) Viewed 1460 times
User avatar
dmasterplan
Posts: 143
Joined: Thu Mar 17, 2022 4:04 am
Location: Philippines

Re: Split comma separated values from Text component

Post by dmasterplan »

dsPackageInCharge.TextValue = "";
string Variable1 = dsPackages.Package_In_Charge;

var i = 1;
using (System.IO.StringReader sr = new System.IO.StringReader(Variable1.Replace("-","\n")))
{
string line;
while ((line = sr.ReadLine()) != null)
{
dsPackageInCharge.TextValue += i++.ToString() + ". " + line + "\n";
}
}

We solved it already. It's just not been reset, so we had added dsPackageInCharge.TextValue = "";
in the first line.

Great Thanks
Lech Kulikowski
Posts: 7338
Joined: Tue Mar 20, 2018 5:34 am

Re: Split comma separated values from Text component

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply