Click here to Skip to main content
15,920,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,
who I can save just the integer value from textbox value, for example
if the: textbox.text = "hello-1234G"
I want the variable A to have the value of: hello-1234G
and variable B to has the value of : 1234

thanks

What I have tried:

nothing ,nothing ,nothing ,nothing ,nothing nothing
Posted
Updated 26-Feb-18 20:59pm

Use a Regex: Regex Class (System.Text.RegularExpressions)[^]
\d+
Should do it.
 
Share this answer
 
Comments
Member 13199484 27-Feb-18 3:46am    
I read it really helpful, for sure I will do it
OriginalGriff 27-Feb-18 3:48am    
You're welcome!
string a = textbox.text;  // hello-1234G
string b = string.Join("", input.Where(k => char.IsNumber(k)));  // 1234
 
Share this answer
 
Comments
Member 13199484 27-Feb-18 3:45am    
Oh, its working, thank you
if may I ask another question, I want to fetch data from database which also has the same format so I want to check the numeric value just for example:
the database table:
Id name
000001 Hello-1234g
000002 Hello-1235g

so if I enter in textbox the value of :hello-1235g
I want to import the first row just.
Member 13199484 27-Feb-18 4:37am    
its also work against Database
Karthik_Mahalingam 27-Feb-18 5:35am    
okuse ado.net to fetch the data.
select * from table where name = 'Hello-1234g'

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