0
string test = "Account.Parameters[\"AccountNumber\"].Caption";
string new = test.Trim("[");

I want output "AccoutNumber". I have tried the below code but not getting the desired result:

string[] test = "Transaction.Parameters[\"ExpOtherX\"].Caption".Split('[');
string newvalue = test[1];
Gilad Green
  • 36,708
  • 7
  • 61
  • 95
Shivam
  • 83
  • 1
  • 1
  • 11

3 Answers3

1

Just use Split with two delimiters:

string[] test = "Transaction.Parameters[\"ExpOtherX\"].Caption".Split('[', ']');
string newvalue = test[1];
stop-cran
  • 4,229
  • 2
  • 30
  • 47
1

You can also use Regex:

string test = "Account.Parameters[\"AccountNumber\"].Caption";
var match = System.Text.RegularExpressions.Regex.Match(test, ".*?\\.Parameters\\[\"(.*?)\"]");
if (match.Success)
{
    Console.WriteLine(match.Groups[1].Value);
}

.*? is a non greedy wildcart capture, so it will match your string until it reaches the next part (in our case, it will stop at .Parameters[", match the string, and then at "])

It will match .Parameters["..."]., and extract the "..." part.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
0

you can do a Split to that string...

string test = "Account.Parameters[\"AccountNumber\"].Caption";
string output = test.Split('[', ']')[1];
Console.WriteLine(output);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97