Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,
I have some lines of a file and i have to get from it as a string just the firsts characters.
The text is:
...
(spaces) UWORD (spaces) /* data type */
(spaces) UBYTE (spaces) /* data type */
....

I have to get the "UWORD", "UBYTE" without any space and without "/*data type..."

I tried with character by character but nothing, and in Regex i can't figured out how can i do it.
Thanks a lot!

What I have tried:

Regex pattern = new Regex("(I DON'T KNOW)", RegexOptions.None);

// for regex
or if there is another method...
Posted
Updated 12-Sep-18 3:20am
v2

1 solution

You could try:
C#
string rx = @"^\s*(?<Type>[A-Z]+)\s*.*$"

What you want to capture would be captured under the named groupe Type.
Hope this helps. There exist several free tools out there to build regular expressions ; you should try one of them :)
 
Share this answer
 
v2
Comments
LRazvan96 13-Sep-18 1:11am    
This does not working. Nothing to show. :(
And i see on internet a lot of sites with regular expressions but noone can build a expression from 0 for my wishes.
phil.o 13-Sep-18 6:19am    
Please show the code you have used; I tested this regular expression before answering, and it allows to extract what you have asked.
LRazvan96 13-Sep-18 8:58am    
Nevermind, i deleted all code and tried with this :
string value = linie.Split(new string[] { " ", "\t" },StringSplitOptions.RemoveEmptyEntries).First();
Sry for trouble.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900