Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

my question is lets say i have a text file with a name "test.txt" inside text file it has "1ab2n3"first i want to read only integers(123) from text file,then the remaining character i-e(abn)Is it possible secondly how to do it i have tried so many things file.Io.readalllines etc
Posted

Hi ,
You can use RegEx to extract the number and/or string.
Try following code

C#
string myStr = "1ab2n3";

string myNumberResult = Regex.Replace(myStr, @"[^\d]", "");
            
                
string myCharResult = Regex.Replace(myStr, @"[\d]", "");


Hope that helps. If it does, mark the it as answer/upvote.
-Milind
 
Share this answer
 
Comments
loraloper_22 10-Oct-12 6:22am    
@Milind thanks a lot
MT_ 10-Oct-12 6:44am    
@loraloper: ANy reason for Downvoting the answer ? When you selected first star...it is downvoting. To upVote, you need to click the right-most star.
loraloper_22 10-Oct-12 6:59am    
M so sorry m new i have updated it.....sorry again
MT_ 10-Oct-12 7:01am    
No problem. Glad that the code was helpful.
 
Share this answer
 

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