Sewder
Sewder

Reputation: 754

How to turn a list of values from a rich textbox to formatted list C#

I have a rich textbox where the user will enter values like this with a line return after each line.

   A12345
   B12345

I want to reformat these values into a like this, to put in a SQL IN clause

   ('A12345', 'B12345')

Note: the last value can't have a [,] following.

Thanks!

Upvotes: 0

Views: 36

Answers (2)

Howard
Howard

Reputation: 3858

Does it work for you?

string result = "(" + string.Join(",", textBox.Text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).Select(s => "'" + s + "'")) + ")";

Upvotes: 1

Prasaz
Prasaz

Reputation: 61

You need to split the text using new line and return carriage.

string[] splitString = textstring.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);`

`

Upvotes: 1

Related Questions