var1 = "Acc_det(acc_code)";
how will get value from Acc_det(acc_code) using var1 ?
var1 = "Acc_det(acc_code)";
how will get value from Acc_det(acc_code) using var1 ?
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
Praveen KumarRank #4 · 79.9K reputationPosted Aug 11, 2025, 12:39 AM EDT
In C# (including .NET MAUI), if you have:
var var1 = "Acc_det(acc_code)";and you want to extract the value inside the parentheses (acc_code in this example), you can use a regular expression or string parsing.
Option 1 – Using Regex
using System.Text.RegularExpressions; string var1 = "Acc_det(acc_code)"; // Pattern: match text inside parentheses var match = Regex.Match(var1, @"\((.*?)\)"); if (match.Success) { string valueInside = match.Groups[1].Value; Console.WriteLine(valueInside); // Output: acc_code }Option 2 – Using String Methods
string var1 = "Acc_det(acc_code)"; int startIndex = var1.IndexOf('(') + 1; int endIndex = var1.IndexOf(')'); if (startIndex > 0 && endIndex > startIndex) { string valueInside = var1.Substring(startIndex, endIndex - startIndex); Console.WriteLine(valueInside); // Output: acc_code }? When to use which?
Regex → cleaner for patterns, even if string format changes slightly.
String Methods → faster and fine for simple cases like this.