I've got a string value with a lot of different characters and I want to get a string contains with permitted characters.
For Example: I've got this string "geeks01$سهیلاطریقی03.02geeks!@!!." but I want to return this value:"0103.سهیلاطریقی02@."
The following Class
is for detecting valid characters. and it works correctly .but I can't find an expression
for persian characters.
Does anyone have any idea for fixing this problem? or any solution for better performance because I care about bottleneck and it must run about 8,000,000 times :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
public static void Main()
{
string str = "geeks01$سهیلاطریقی03.02geeks!@!!.";
splitString(str, true, false, true, new char[] { '@', '.' });
}
static string splitString(string str, bool keepNumber, bool keepEnglishAlpha, bool keepPersianbAlpha, char[] special)
{
StringBuilder value =
new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
if (Char.IsDigit(str[i]) && keepNumber == true)
value.Append(str[i]);
if (keepEnglishAlpha == true)
if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z'))
value.Append(str[i]);
if (keepPersianbAlpha == true)
{
//todo
}
if (special.Length >= 1)
{
foreach (var specialChar in special)
{
if (str[i] == specialChar)
value.Append(str[i]);
}
}
}
return value.ToString();
}
}
}