-
-
-
-
-
-
-
-
-
-
-
-
- public static bool IsBjChar(char c)
- {
- int i = (int)c;
- return i >= 32 && i <= 126;
- }
-
-
-
-
-
-
-
-
- public static bool IsQjChar(char c)
- {
- if (c == ‘\u3000‘) return true;
-
- int i = (int)c - 65248;
- if (i < 32) return false;
- return IsBjChar((char)i);
- }
-
-
-
-
- public static string ToBj(string s)
- {
- if (s == null || s.Trim() == string.Empty) return s;
-
- StringBuilder sb = new StringBuilder(s.Length);
- for (int i = 0; i < s.Length; i++)
- {
- if (s[i] == ‘\u3000‘)
- sb.Append(‘\u0020‘);
- else if (IsQjChar(s[i]))
- sb.Append((char)((int)s[i] - 65248));
- else
- sb.Append(s[i]);
- }
-
- return sb.ToString();
- }
全角空格为12288,半角空格为32
其他字符半角(33-126)与考试.大提示全角(65281-65374)的对应关系是:均相差65248
- public static String QtoB(String input) {
- char c[] = input.toCharArray();
- for (int i = 0; i < c.length; i++) {
- if (c[i] == ‘\u3000‘) {
- c[i] = ‘ ‘;
- }?
- else if (c[i] > ‘\uFF00‘ && c[i] < ‘\uFF5F‘) {
- c[i] = (char) (c[i] - 65248);
- }
- }
- return new String(c);
- }
- public static String BtoQ(String input){
- char c[] = input.toCharArray();
- for ( int i=0; i<c.length;i++ ) {
- if (c[i] ==‘ ‘) {
- c[i] = ‘\u3000‘;
- }
- else if (c[i]<‘\177‘) {
- c[i]= (char) (c[i]+65248);
- }
- }
- return new String(c);
- }