I have a string that could have any sentence in it but somewhere in that string will be the @ symbol, followed by an attached word, sort of like @username you see on some sites.
so maybe the string is “hey how are you” or it’s “@john hey how are you”.
IF there’s an “@” in the string i want to pull what comes immediately after it into its own new string.
in this instance how can i pull “john” into a different string so i could theoretically notify this person of his new message? i’m trying to play with string.contains or .replace but i’m pretty new and having a hard time.
this btw is in c# asp.net
You should really learn regular expressions. This will work for you:
Finds the first occurrence. If you want to find all you can use
Regex.Matches.\Smeans anything else than a whitespace. This means it also makehey @john, how are you=>john,and@john123=>john123which may be wrong. Maybe[a-zA-Z]or similar would suit you better (depends on which characters the usernames is made of). If you would give more examples, I could tune it 🙂I can recommend this page:
http://www.regular-expressions.info/
and this tool where you can test your statements:
http://regexlib.com/RESilverlight.aspx