locked
how to get the numeric in asp.net textbox RRS feed

  • Question

  • User1046245955 posted

    how can i get the NUMBERS only in textbox after the (-) sign using c# .net

    for example:

    PRETTY-GIRL - 23456 

    i need to get 23456 ONLY

    Wednesday, May 23, 2018 12:25 PM

All replies

  • User-1345054863 posted
    string a = "PRETTY-GIRL - 23456".split('-')[2];
    
    //or
    
    string a = yourtextboxId.text.Trim().split('-')[2]

    Wednesday, May 23, 2018 12:30 PM
  • User1724605321 posted

    Hi paminchever,

    You can use  TryParse method, which returns a bool indicating if the conversion was successful :

                string testValue = "PRETTY-GIRL - 23456";
    
                String[] substrings = testValue.Split('-');
    
                int value;
                foreach (var item in substrings)
                {
                    if (int.TryParse(item.Trim(), out value))
                    {
                        break;
                    }
                }

    You can get the number 23456 in value variable.

    Best Regards,

    Nan Yu 

    Thursday, May 24, 2018 6:29 AM