Verilen metni bir arttırma (bir sonraki fiş nosunu üretme gibi)
public static string setofchars(char startchar, char stopchar)
{
string tmp = "";
if (Convert.ToByte(startchar) < Convert.ToByte(stopchar))
for (int i = Convert.ToByte(startchar); i <= Convert.ToByte(stopchar); i++) tmp += (char)i;
else
for (int i = Convert.ToByte(stopchar); i <= Convert.ToByte(startchar); i++) tmp += (char)i;
return tmp;
}
public static string incStr(string ck, bool lead, int len)
{
int say, ln;
string tmp = "";
string str = setofchars('0', '9');
while (ck != "" && (str.IndexOf(ck[ck.Length - 1]) != -1))
{
tmp = ck[ck.Length - 1] + tmp;
ck = ck.Remove(ck.Length - 1, 1);
}
if (tmp == "") tmp = "00001";
ln = tmp.Length;
say = Convert.ToInt32(tmp);
say++;
tmp = say.ToString();
while (tmp.Length < ln) tmp = "0" + tmp;
tmp = ck + tmp;
if (lead)
{
while (tmp.Length < len) tmp = "0" + tmp;
}
return tmp;
}
Örn : increase string
incStr("F001",false,4) -> F002
incStr("F001",true,5) -> 0F002