Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a value of ACCOUNTS MGT & TREASURY - OFFICE OF THE ASSISTANT VICE PRESIDENT - 1231

how do i only get ACCOUNTS MGT & TREASURY - OFFICE OF THE ASSISTANT VICE PRESIDENT?

What I have tried:

i tried this code
var onlyLetters = new string(myString.Where(char.IsLetter).ToArray());
but it will delete all the space
i only want to erase the - 1231
Posted
Updated 3-Feb-19 22:44pm

If you want to remove 123 (digits) from string, you can use Regex.Replace method[^]. See:

C#
string s = @"ACCOUNTS MGT & TREASURY - OFFICE OF THE ASSISTANT VICE PRESIDENT - 1231";
string pattern = @"\d";
string replacement = string.Empty;
var result = Regex.Replace(s, pattern, replacement, RegexOptions.IgnoreCase);


Result:
ACCOUNTS MGT & TREASURY - OFFICE OF THE ASSISTANT VICE PRESIDENT -
 
Share this answer
 
v3
Or you follow your LINQ approach. Just a littlebit modifyed
becouse if you just want do get rid of the numeric digits and keep all the text and symbols

C#
var myString = "ACCOUNTS MGT & TREASURY - OFFICE OF THE ASSISTANT VICE PRESIDENT - 1231";
var onlyLetters = new String(myString.Where(_ => !char.IsDigit(_)).ToArray());

=> ACCOUNTS MGT & TREASURY - OFFICE OF THE ASSISTANT VICE PRESIDENT - 
 
Share this answer
 
 
Share this answer
 
v2
Comments
Maciej Los 4-Feb-19 4:10am    
OP wants to remove digits from string...
Wastedtalent 4-Feb-19 4:34am    
Yes i suppose the question was phrased badly, either way, as per your answer, Regex would do the job. Maybe I could have put abetter link in.

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