working with a string from a textbox

  • Thread starter Thread starter AllcompPC
  • Start date Start date
A

AllcompPC

I have a value in a text box pulled in from a dataadapter. This text might
be "Black White Tan". If it is, then I want to have three other boxes and
will fill with these colors. That part I know how to do, but I have not
really had to manipulate a string before. How would I pull apart the above
string to assign the colors to three boxes?

Just some other information, this value will always contain spaces between
the colors, this value is required; this value is either one, two or three
colors - never any more.

Thanks for any information.

Brad
 
Hi, AllcompPC

You can use regex (see Regex class) to do what you want to do. Basic
expression, which can get you started is

Match m = Regex.Match(inputString, "(\w+\s)+"

You can check Groups, Matches and Captures collections, what they have
inside.
As soon as you have complete string with color name you can create your
color using this string. See Color class.

HTH
Alex
 
Use String.Split to split your value into different color strings
Then use Color.FromName to get a color object

/claes
 
Back
Top