Remove the special Character from string. AND Get first four characer from string.
public string RemoveSpecialChars(string str)
{
string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "_", "(", ")", ":", "|", "[", "]", "=", "==" };
for (int i = 0; i < chars.Length; i++)
{
if (str.Contains(chars[i]))
{
str = str.Replace(chars[i], "");
}
}
return str;
}
Get first four characer from string.
public string GetFirstFourCharacters(string s)
{
return (s.Length < 4) ? s : s.Substring(0, 4);
}
public string RemoveSpecialChars(string str)
{
string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "_", "(", ")", ":", "|", "[", "]", "=", "==" };
for (int i = 0; i < chars.Length; i++)
{
if (str.Contains(chars[i]))
{
str = str.Replace(chars[i], "");
}
}
return str;
}
Get first four characer from string.
public string GetFirstFourCharacters(string s)
{
return (s.Length < 4) ? s : s.Substring(0, 4);
}
No comments:
Post a Comment