Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Extract part of the string that starts with specific word

I have multiple strings that looks:

this is ab-skdn string
ab-sdhnif my string

For each string, I need to pull the part that is ab-**
For example I need ab-skdn and ab-sdhnif

How could I do that using C#

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My code would look like something:

var myString = "this is ab-skdn string"
match = "ab-skdn"

>Solution :

Use a regex to find the matches. A simple regex that does what you need is:

ab-[a-z]*

Since you didn’t provide any code I can’t provide an example for how to use a regex in your context, but there are plenty of examples out there. A quick google search on how to use Regex in C# should get you started. The link I provided also has some good examples.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading