Sunday, March 6, 2011

Convert Comma-Delimited String To Array & Loop

--set whatever delimiter you want to use:
char delimiter = ',';


--Get the string you want to turn to an array (in this case, I use the app.config)
string s = ConfigurationManager.AppSettings["StringToReplace"];

--Declare an array for your string
string[] stringToReplace = s.Split(delimiter);

--Finally, if you want to loop through your new array:
string content = String.Empty;

for (int j = 0; j <> 0; j++)
{
content = stringToReplace[j];
}

No comments:

Post a Comment