Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%\\-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
Second Solution. A nice OneLiner as Taemyr suggested:
public string RemoveUnwantedChar(string input) {
return Regex.Replace(input, "[^0-9numkMGHzVs%\\-.]", "");
}
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
// Edit2 Escaped the Dash for more Info: http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped https://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%\\-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
Second Solution. A nice OneLiner as Taemyr suggested:
public string RemoveUnwantedChar(string input) {
return Regex.Replace(input, "[^0-9numkMGHzVs%\\-.]", "");
}
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
// Edit2 Escaped the Dash for more Info: http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%\\-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
Second Solution. A nice OneLiner as Taemyr suggested:
public string RemoveUnwantedChar(string input) {
return Regex.Replace(input, "[^0-9numkMGHzVs%\\-.]", "");
}
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
// Edit2 Escaped the Dash for more Info: https://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%9numkMGHzVs%\\-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
Second Solution. A nice OneLiner as Taemyr suggested:
public string RemoveUnwantedChar(string input) {
return Regex.Replace(input, "[^0-9numkMGHzVs%\\-.]", "");
}
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
// Edit2 Escaped the Dash for more Info: http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%\\-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
Second Solution. A nice OneLiner as Taemyr suggested:
public string RemoveUnwantedChar(string input) {
return Regex.Replace(input, "[^0-9numkMGHzVs%\\-.]", "");
}
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
// Edit2 Escaped the Dash for more Info: http://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
stringStringBuilder correctStringstringBuilder = "";new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%-.]")) {
correctString += stringBuilder.Append(match.ToString());
}
return correctString;stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
string correctString = "";
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%-.]")) {
correctString += match.ToString();
}
return correctString;
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
Same answer as on SO
Whenever you have to search for literals. Regex is the way to go.
public string RemoveUnwantedChar(string input) {
StringBuilder stringBuilder = new StringBuilder();
foreach (var match in Regex.Matches(input, "[0-9numkMGHzVs%-.]")) {
stringBuilder.Append(match.ToString());
}
return stringBuilder.ToString();
}
- Code is shorter
- Very easy to expand
- Easy to read
- Easy to follow the Code
// Edit from String concatenation to StringBuilder implementation for better Performace especially for large inputs