I have data in a string, email
and id
, in the format as shown below:
string s = "{email:[email protected]}{id:AB12345}";
I just want to remove curly brackets and extract the email and id from the above string in a variable as below.
string email = "[email protected]";
string id = "AB12345";
I have tried string.Format
and other formatting. Since email and id size can vary, I can't find a solution.
Use can use Regex.
var match = Regex.Match("{email:[email protected]}{id:AB12345}", @"\{email:(.+)\}\{id:(.+)\}");
var email = match.Groups[1].Value;
var id = match.Groups[2].Value;
PS:
The pattern (.+)
means that Email and the Id at least have 1 character, otherwise the match will not find the email and id, if those can be empty you can change it into (.*)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With