我哭啊,哪位大神帮我翻译一句VB的代码到C# ?
本帖最后由 wuhuanghao 于 2014-03-01 19:29:41 编辑
Dim i, s
for i = 1 to Len(str)
s = s & (asc(mid(str, i, 1)) xor key) & ","
next
'----------
Dim t
t = (DateDiff("s", #1/1/1970#, Now) * 1000) / 100
s = s & t
'----------
s = s & key & m
'----------
x = Split(str, ",")
m = Right(x(Ubound(x)), 1)
key = Mid(x(Ubound(x)), len(x(Ubound(x)))-3+1, 2)
'Wscript.Echo "M = " & m
'Wscript.Echo "Key = " & key
'----------
Dim i, s
for i = lbound(x) to (ubound(x) - 1)
s = s & Chr(Int(x(i)) xor key)
next
这两段代码翻译成C#的代码,应该怎么写?
------解决方案--------------------int i = 0;
string s = "";
for (i = 1; i <= str.Length; i++)
s += (str.SubString(i - 1, 1)[0] ^ key).ToString() + ",";
DateTime t = new TimeSpan(DateTime.Now.Tick, new DateTime(1970, 1, 1).Tick).TotalSeconds * 10;
s += t.ToString();
s += key + m;
------解决方案--------------------就是数组与字符的处理,
由于不知道你str的内容,转换上可能不对,大概这样
string Str = null;
string m = null;
Int64 key ;
string s = "";
Str = "1234,2346,3668,6789,1345,1267";
string[] x = null;
x = Str.Split(',');
string L =x[x.GetUpperBound(0)];
m = L.Substring(L.Length - 1, 1);
key =Convert.ToInt64(L.Substring(L.Length - 3 + 1, 2));
for (int i =x.GetLowerBound(0); i <= x.GetUpperBound(0)-1 ; i++)