0

I have the following stored in a string.

var _status = "Unknown,Enabled,DisabledAccount,Enabled,Password Does Not Expire,Disabled,Password Does Not Expire,Enabled, Password Does Not Expire"

Desired string so that I can use it in MySQL IN Statement.

var stat = "'Unknown','Enabled','Disabled Account','Enabled, Password Does Not Expire','Disabled, Password Does Not Expire','Enabled, Password Does Not Expire'"

My Code:

string stat = "";
string[] devices = _status.Split(',');
foreach (var d in devices)
{
    stat += "'" + d + "',";
}

stat = stat.TrimEnd(',');

Output

var stat = "'Unknown','Enabled','Disabled Account','Enabled',' Password Does Not Expire','Disabled',' Password Does Not Expire','Enabled',' Password Does Not Expire '"

Thanks

10
  • 4
    What is the problem? Looks like you got your desired output Commented Oct 18, 2019 at 16:09
  • 1
    Regex.Split(_status, "(?<!^),(?!\s)") Commented Oct 18, 2019 at 16:12
  • 4
    How would you know that some commas are there as separators and some are part of a sentence. Use another separator (or use a completely different format). Commented Oct 18, 2019 at 16:12
  • 1
    How do you determine that Enabled,Password Does Not Expire must not be split on the comma? Commented Oct 18, 2019 at 16:13
  • 1
    This will be crazy-vulnerable to sql injection issues. Commented Oct 18, 2019 at 16:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.