Page 1 of 1

Split comma separated values from Text component

Posted: Thu Mar 31, 2022 8:00 am
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?

Re: Split comma separated values from Text component

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

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

Thank you.

Re: Split comma separated values from Text component

Posted: Thu Mar 31, 2022 10:50 am
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!

Re: Split comma separated values from Text component

Posted: Thu Mar 31, 2022 1:11 pm
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.

Re: Split comma separated values from Text component

Posted: Thu Mar 31, 2022 2:20 pm
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.

Re: Split comma separated values from Text component

Posted: Fri Apr 01, 2022 12:49 am
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

Re: Split comma separated values from Text component

Posted: Mon Apr 04, 2022 8:02 pm
by Lech Kulikowski
Hello,

You are welcome.