JAVA
代码:中文转英文
public static void main(String[] args) {
String Node = "我爱中国!()";
String newNode = null;
String allConvertNode = null;
if (Node.contains("(") && Node.contains(")")) {
newNode = Node.replaceAll("(", "(");
allConvertNode = newNode.replace(")", ")");
} else if (!(Node.contains("(")) && Node.contains(")")) {
allConvertNode = Node.replaceAll(")", ")");
} else if (Node.contains("(") && !(Node.contains(")"))) {
newNode = Node.replaceAll("(", "(");
allConvertNode = newNode;
} else {
allConvertNode = Node;
}
System.out.println(allConvertNode);
}
输出:
E:\Java\bin\java.exe
我爱中国!()
public static void main(String[] args) {
String a = "我爱中国!()";
StringBuilder b = new StringBuilder("");
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) == '(') {
b.append("(");
} else if (a.charAt(i) == ')') {
b.append(")");
} else {
b.append(a.charAt(i));
}
}
System.out.println(b);
}
输出:
E:\Java\bin\java.exe
我爱中国!()
C#
代码:
//英文括号转中文括号
public static string ToSBC(string input)
{
char[] c = input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] == 32)
{
c[i] = (char)12288; continue;
}
if (c[i] < 127) c[i] = (char)(c[i] + 65248);
}
return new string(c);
}
//中文括号转英文括号
public static string ToDBC(string input)
{
char[] c = input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] == 12288)
{
c[i] = (char)32; continue;
}
if (c[i] > 65280 && c[i] < 65375)
c[i] = (char)(c[i] - 65248);
}
return new string(c);
}