I have string like below
IN ('Test 123','12345','163')
NOT IN ('Test 123','12345','163')
want to get like 'Test 123','12345','163' remove those IN and NOT IN and '(' and ')' using c#
I have string like below
IN ('Test 123','12345','163')
NOT IN ('Test 123','12345','163')
want to get like 'Test 123','12345','163' remove those IN and NOT IN and '(' and ')' using c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Feb 3, 2023, 3:55 AM EST
Easiest would be
var str1="IN ('Test 123','12345','163')"; var str2="NOT IN ('Test 123','12345','163')"; var res1=str1.Replace("IN","").Replace("(","").Replace(")","").Replace("NOT","").Replace(" ",""); var res2=str2.Replace("IN","").Replace("(","").Replace(")","").Replace("NOT","").Replace(" ","");Or better create one extension method
public static MyExtensionForStrings { public static string RemoveSpecialAlphaSps(this string str) { return str.Replace("IN","").Replace("(","").Replace(")","").Replace("NOT","").Replace(" ",""); } }use above extension method as
var res1=str1.RemoveSpecialAlphaSps(); var res2=str2.RemoveSpecialAlphaSps();or best one
public static MyExtensionForStrings { public static string RemoveSpecialAlphaSps(this string str) { return str.Replace("IN (", "").Replace("NOT","").TrimEnd(')'); } }Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 3, 2023, 3:28 AM EST
Hello Jhon,
Use below code.
string inString = "IN ('Test 123','12345','163')"; int startIndex = inString.IndexOf("(") + 1; int endIndex = inString.IndexOf(")"); string inStringResult = inString.Substring(startIndex, endIndex - startIndex).Trim(); string notInString = "NOT IN('Test 123','12345','163')"; int notInStringStartIndex = notInString.IndexOf("(") + 1; int notInStringEndIndex = notInString.IndexOf(")"); string notInStringResult = notInString.Substring(notInStringStartIndex, notInStringEndIndex - notInStringStartIndex).Trim();Thanks
Naimish
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 3, 2023, 3:59 AM EST
Hi Jhon,
You can also use below code.
string inString = "IN ('Test 123','12345','163')"; string result = inString.Replace("IN (", "").TrimEnd(')'); string outInput = "NOT IN ('Test 123','12345','163')"; string result1 = outInput.Replace("NOT IN (", "").TrimEnd(')');Thanks
Naimish