那不是蛮简单的嘛.. class Program { static void Main(string[] args) { string s = "15817034063"; if (s.Length % 2 > 0) { s = s + "F"; } char[] arr = s.ToCharArray(); for (int i = 0; i < arr.Length; i += 2) { char c = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = c; } string result = new string(arr); Console.WriteLine(result); } }
{ static void Main(string[] args)
{
string s = "15817034063"; if (s.Length % 2 > 0) { s = s + "F"; } char[] arr = s.ToCharArray(); for (int i = 0; i < arr.Length; i += 2)
{
char c = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = c;
} string result = new string(arr); Console.WriteLine(result);
} }
using System;
using System.Text;namespace ProjectServer
{
class Program
{
static void Main(string[] args)
{
string s = "15817034063";//5118074360F3
StringBuilder newString = Exchange(s);
Console.WriteLine(newString);
}
static StringBuilder Exchange(string str)
{
StringBuilder sb = new StringBuilder(str);
if (sb.Length % 2 != 0)
sb.Append('F');
int length = sb.Length;
for (int i = 0; i < length; i += 2)
{
char ch = sb[i];
sb[i] = sb[i + 1];
sb[i + 1] = ch;
}
return sb;
}
}
}
string s = "15817034063";
if (s.Length < 12)
{
s += "F";
}
char[] c= s.ToCharArray();
char temp = ' '; //赋一个空格字符
for (int i = 0; i < c.Length-1; i+=2)
{
temp = c[i];
c[i] = c[i + 1];
c[i + 1] = temp;
}
s = "";
for (int i = 0; i < c.Length; i++)
{
s += c[i].ToString();
}
MessageBox.Show(s);
str2 = "15817034063";
str2 = str2.Length % 2 == 0 ? str2 : (str2 + "F");
int step = str2.Length;
System.Text.StringBuilder result = new System.Text.StringBuilder();
for (int i = 0; i < step; i+=2)
{
result.Append(str2[i + 1].ToString() + str2[i]);
}
return result.ToString();
{
if (str.Length % 2 == 1)
{
str += "F";
} char[] c = str.ToCharArray();
char tmp = char.MinValue; for (int i = 0; i < c.Length; i += 2)
{
tmp = c[i];
c[i] = c[i + 1];
c[i + 1] = tmp;
} return new string(c);
}
public void resever()
{
string s = "15817034063";
char temp=' ';
if (s.Length % 2 != 0) { s += "F"; }
char[] len = s.ToCharArray();
for(int i=0;i<len.Length;i+=2)
{
temp = len[i];
len[i] = len[i + 1];
len[i + 1] = temp;
}
Console.WriteLine(len);
}亲手验证,绝对正确,信誉保证!
string s = "15817034063";
s += "FFFFFFFFFFFF";
char[] arry = s.ToCharArray(0, 12);
for (int i = 0; i < arry.Length; i+=2)
{
char t = arry[i];
arry[i] = arry[i + 1];
arry[i + 1] = t;
}
Console.WriteLine(arry);