我正在寻找一个函数,它可以接收如下示例中的一行客户信息:
125478744|John|Smith|1234567890123456|50.00|Dinner
然后,我将拆分该信息并使用此函数将其放入字符串数组中:
private static string[] ScrubData(string text)
{
//here is where the string is broken apart
String[] customerInfo = text.Split('|');
return customerInfo;
}
然后我需要另一个函数来执行以下操作:
用 1 到 9 之间的九个随机数字替换第一列数字,即社会安全号码。
然后第三列是客户的姓氏,我需要为姓氏的每个字符生成随机字母并替换它们。
在第 4 列中,这将是帐号,我需要将除最后 4 之外的所有数字替换为“X”。
在第 5 列中,即金额,我需要检查金额是否大于 100。如果是,我需要在信息行末尾创建一个新列,如果金额是,则说明是或否大于 100。
我将使用以下随机数生成器和随机字符生成器函数:
public static char GetRandomLetter()
{
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random rand = new Random();
int num = rand.Next(0, chars.Length -1);
return chars[num];
}
public static int GetRandomNumber()
{
Random rnd = new Random();
int ranNum = rnd.Next(10);//creates random number between 0 and 9
return ranNum;
}
提前致谢!