实际遇到的问题:在串口获取码表数据的时候,有的码表传到电脑上的数字顺序是颠倒的,即:123.45,会显示为54.321。需要重新处理数据。方法很多,也不难实现,现在列举其中5个。
public string DZ1(string A) { string ShuChu = ""; foreach (char m in A) { ShuChu = m.ToString() + ShuChu; } return ShuChu; } public string DZ2(string A) { string ShuChu = ""; for (int i = 0; i < A.Length; i++) { char temp = A[i]; ShuChu = temp.ToString() + ShuChu; } return ShuChu; } public string DZ3(string A) { string ShuChu = ""; for (int i = 0; i < A.Length; i++) { ShuChu = A.Substring(i, 1) + ShuChu; } return ShuChu; } public string DZ4(string A) { string ShuChu = ""; for (int i = A.Length - 1; i >= 0; i--) { ShuChu += A.Substring(i, 1); } return ShuChu; } public string DZ5(string A) { char[] aa = A.ToCharArray(); Array.Reverse(aa); return new string(aa); }