i have a value for ex “abc - xyz - jkl”
and my result should be “abc - xyz” in a string
i want a single line code.
Thanks
Thank you so much
1 Like
Try this-
Use the Split method to split the inputString
based on the delimiter “-”. This will return an array of substrings.
Assign splitArray = inputString.Split("-"c)
Use the Substring method to extract the first two substrings from the split array, which correspond to “abc” and “xyz”. Concatenate them back together using the delimiter “-”.
Assign result = String.Join(“-”, splitArray.Take(2))
The resulting string will be “abc - xyz”.
Thanks!!
Hi @mark_01 ,
Here’s using regex:
System.Text.RegularExpressions.Regex.Match(StringVariable,"(\w+[\s-]+\w+)").Value.ToString
Regards,
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.