Search code examples
asp.netvb.netsubstringhashtag

asp.net Substring from specific string to the end of the word


I have a multiline textbox that user may type whatever he wants to for example,

"Hello my name is #Konstantinos and i am 20 #years old"

Now i want to place a button when is pressed the output will be #Konstantinos and #years -

Is that something that can be done using substring or any other idea?

Thank you in advance


Solution

  • If all that you want is HashTags(#) from the entire string, you can perform simple .Split() and Linq. Try this:

    C#

    string a = "Hello my name is #Konstantinos and i am 20 #years old";
    var data = a.Split(' ').Where(s => s.StartsWith("#")).ToList();
    

    VB

    Dim a As String = "Hello my name is #Konstantinos and i am 20 #years old" 
    Dim data = a.Split(" ").Where(Function(s) s.StartsWith("#")).ToList()