[英]Adding special characters to an array
I have a function that adds capitals, lowercase, and 0-9 to a character array and now i want to add special characters such as !@#$%^&*()
. 我有一个向字符数组添加大写,小写和0-9的函数,现在我想添加特殊字符,例如
!@#$%^&*()
。 The format for my array goes like this: 我的数组的格式如下:
for (char ch = '0'; ch <= '9'; ++ch)
tmp.append(ch);
for (char ch = 'a'; ch <= 'z'; ++ch)
tmp.append(ch);
for (char ch = 'A'; ch <= 'Z'; ++ch)
tmp.append(ch);
symbols = tmp.toString().toCharArray();
How do I add the special characters, using the same format if possible, without adding them one by one? 如何添加特殊字符,如果可能的话,使用相同的格式,而不一一添加?
I agree with the comment Elliott made. 我同意艾略特的评论。 you can add the characters !"#$%&'()*+,-./ by using
您可以使用添加字符!“#$%&'()* +,-。/
for(int i = 33 ; i < 48; i++)
tmp.append(Character.toChars(i))
The ASCII values of the characters which I listed is from 33 to 48, they will be converted to the keyboard characters and can be appended. 我列出的字符的ASCII值从33到48,它们将转换为键盘字符并可以附加。
如果tmp是StringBuilder或StringBuffer,则可以在一个方法调用中附加所有字符:
tmp.append( "!@#$%^&*()" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.