Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string list = "Fred,Sam,Mike,Sarah";
- string newList = "'Fred','Sam','Mike','Sarah'";
- int number = 0;
- string newList = "";
- foreach (string item in list.Split(new char[] {','}))
- {
- if (number > 0)
- {
- newList = newList + "," + "'" + item + "'";
- }
- else
- {
- newList = "'" + item + "'";
- }
- number++;
- }
- string s = "A,B,C";
- string replaced = "'"+s.Replace(",", "','")+"'";
- string[] bits = list.Split(','); // Param arrays are your friend
- for (int i=0; i < bits.Length; i++)
- {
- bits[i] = "'" + bits[i] + "'";
- }
- return string.Join(",", bits);
- return list.Split(',').Select(x => "'" + x + "'").JoinStrings(",");
- public static string JoinStrings<string>(this IEnumerable<string> source,
- string separator)
- {
- StringBuilder builder = new StringBuilder();
- bool first = true;
- foreach (T element in source)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- builder.Append(separator);
- }
- builder.Append(element);
- }
- return builder.ToString();
- }
- string nameList = "Fred,Sam,Mike,Sarah";
- string[] names = nameList.Split(',');
- string quotedNames = "'" + string.Join("','", names) + "'";
- string[] splitList = list.Split(',');
- string newList = "'" + string.Join("','", splitList) + "'";
- var s = "Fred,Sam,Mike,Sarah";
- alert(s.replace(/b/g, "'"));
- string list = "Fred,Sam,Mike,Sarah";
- string[] splitList = list.Split(',');
- for (int i = 0; i < splitList.Length; i++)
- splitList[i] = String.Format("'{0}'", splitList[i]);
- string newList = String.Join(",", splitList);
- Regex regex = new Regex(
- @"b",
- RegexOptions.ECMAScript
- | RegexOptions.Compiled
- );
- string list = "Fred,Sam,Mike,Sarah";
- string newList = regex.Replace(list,"'");
- string list = "Fred,Sam,Mike,Sarah";
- StringBuilder sb = new StringBuilder();
- string[] listArray = list.Split(new char[] { ',' });
- for (int i = 0; i < listArray.Length; i++)
- {
- sb.Append("'").Append(listArray[i]).Append("'");
- if (i != (listArray.Length - 1))
- sb.Append(",");
- }
- string newList = sb.ToString();
- Console.WriteLine(newList);
Add Comment
Please, Sign In to add comment