Sean
Sean

Reputation: 907

Winform split up string in a text box

Sorry, newb question that I can't seem to work out.

I'm connecting to a server via a php file that is return a list of the files held on there like so:

511157.jpg|Koala.jpg|VIDEO0031.3gp|test_folder.folder

However I want my text box to display them like so

511157.jpg

Koala.jpg

VIDEO0031.3gp

test_folder.folder

I've been trying this at the moment but it isn't doing what I'm wanting it to do:

textBox1.Text = string.Join(Environment.NewLine, result);

I know this is a simple thing to do, but I can't seem to get my head to function properly. Could someone please help me out?

I should note I have no idea what the files will be on the server. I'm getting this information by calling the following:

  using (var client = new WebClient())
        {
             result = client.DownloadString("http://server.foo.com/images/getDirectoryList.php");
        }

Anything could be on this.

Upvotes: 1

Views: 2128

Answers (5)

Tushar Gupta
Tushar Gupta

Reputation: 15913

You can do this by .split as

String s=511157.jpg|Koala.jpg|VIDEO0031.3gp|test_folder.folder;

textBox1.Text = string.Join(Environment.NewLine, s.Split('|'));

Upvotes: 0

Jesko R.
Jesko R.

Reputation: 827

you can just use Regex.Replace() for that simple case:

textBox1.Text = Regex.Replace("511157.jpg|Koala.jpg|VIDEO0031.3gp|test_folder.folder", "\\|", "\r\n")

Upvotes: 1

embee
embee

Reputation: 1007

You can split by the pipe character first, then join:

string.Join(Environment.NewLine, "511157.jpg|Koala.jpg|VIDEO0031.3gp|test_folder.folder".Split('|'))

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460108

You have to use String.Split:

textBox1.Lines = result.Split('|');

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564413

You need to split the text first:

textBox1.Text = string.Join(Environment.NewLine, result.Split('|'));

Upvotes: 4

Related Questions