当前位置: 首页>>代码示例>>C#>>正文


C# String.charAt方法代码示例

本文整理汇总了C#中String.charAt方法的典型用法代码示例。如果您正苦于以下问题:C# String.charAt方法的具体用法?C# String.charAt怎么用?C# String.charAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在String的用法示例。


在下文中一共展示了String.charAt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: decode

 public static Long decode(String nm)
 {
     int radix = 10;
     int index = 0;
     boolean negative = false;
     Long result;
     if (nm.length() == 0)
     throw new NumberFormatException("Zero length string");
     char firstChar = nm.charAt(0);
     // Handle sign, if present
     if (firstChar == '-') {
     negative = true;
     index++;
     } else if (firstChar == '+')
     index++;
     // Handle radix specifier, if present
     if (nm.startsWith(new String("0x"), index) || nm.startsWith(new String("0X"), index)) {
     index += 2;
     radix = 16;
     }
     else if (nm.startsWith(new String("#"), index)) {
     index ++;
     radix = 16;
     }
     else if (nm.startsWith(new String("0"), index) && nm.length() > 1 + index) {
     index ++;
     radix = 8;
     }
     if (nm.startsWith(new String("-"), index) || nm.startsWith(new String("+"), index))
     throw new NumberFormatException("Sign character in wrong position");
     try {
     result = Long.valueOf(nm.substring(index), radix);
     result = negative ? Long.valueOf(-result.longValue()) : result;
     } catch (NumberFormatException) {
     // If number is Long.MIN_VALUE, we'll end up here. The next line
     // handles this case, and causes any genuine format error to be
     // rethrown.
     String constant = negative ? new String("-" + nm.substring(index))
                                : nm.substring(index);
     result = Long.valueOf(constant, radix);
     }
     return result;
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:43,代码来源:Long.cs

示例2: reverseWords

    public String reverseWords(String s)
    {
        if (s == null)
        {
            return s;
        }

        int begin = 0;
        int end = 0;
        while (begin < s.length() && s.charAt(begin) == ' ')
        {
            begin++;
        }
        if (begin == s.length())
        {
            return "";
        }

        if (s.length() <= 1)
        {
            return s;
        }
        StringBuilder result = new StringBuilder("");
        while (begin < s.length() && end < s.length())
        {
            while (begin < s.length() && s.charAt(begin) == ' ')
            {
                begin++;
            }
            if (begin == s.length())
            {
                break;
            }
            end = begin + 1;
            while (end < s.length() && s.charAt(end) != ' ')
            {
                end++;
            }
            if (result.length() != 0)
            {
                result.insert(0, " ");
            }
            if (end < s.length())
            {
                result.insert(0, s.substring(begin, end));
            }
            else
            {
                result.insert(0, s.substring(begin, s.length()));
                break;
            }
            begin = end + 1;
        }
        return result.toString();
    }
开发者ID:einstenwolfgang,项目名称:leetcode-exercise,代码行数:55,代码来源:Reverse+Words+in+a+String.cs

示例3: parseLong

 public static long parseLong(String s, int radix)
 {
     if (s == null) {
     throw new NumberFormatException("null");
     }
     if (radix < Character.MIN_RADIX) {
     throw new NumberFormatException("radix " + radix +
                                     " less than Character.MIN_RADIX");
     }
     if (radix > Character.MAX_RADIX) {
     throw new NumberFormatException("radix " + radix +
                                     " greater than Character.MAX_RADIX");
     }
     long result = 0;
     boolean negative = false;
     int i = 0, len = s.length();
     long limit = -Long.MAX_VALUE;
     long multmin;
     int digit;
     if (len > 0) {
     char firstChar = s.charAt(0);
     if (firstChar < '0') { // Possible leading "+" or "-"
         if (firstChar == '-') {
             negative = true;
             limit = Long.MIN_VALUE;
         } else if (firstChar != '+')
             throw NumberFormatException.forInputString(s);
         if (len == 1) // Cannot have lone "+" or "-"
             throw NumberFormatException.forInputString(s);
         i++;
     }
     multmin = limit / radix;
     while (i < len) {
         // Accumulating negatively avoids surprises near MAX_VALUE
         digit = Character.digit(s.charAt(i++),radix);
         if (digit < 0) {
             throw NumberFormatException.forInputString(s);
         }
         if (result < multmin) {
             throw NumberFormatException.forInputString(s);
         }
         result *= radix;
         if (result < limit + digit) {
             throw NumberFormatException.forInputString(s);
         }
         result -= digit;
     }
     } else {
     throw NumberFormatException.forInputString(s);
     }
     return negative ? result : -result;
 }
开发者ID:jason-persson,项目名称:LibPhoneNumberPortable,代码行数:52,代码来源:Long.cs

示例4: fromChessNotation

            public static CBSquare fromChessNotation(String
								  square)
            {
                if (square == null
                    || (square =
                    square.trim ()).length () != 2)
                    return null;

                square = square.toLowerCase ();
                char ch = square.charAt (0);
                if (ch < 'a' || ch > 'h')
                    return null;
                int file = ch - 'a';
                ch = square.charAt (1);
                if (ch < '1' || ch > '8')
                    return null;
                int rank = ch - '1';

                return new CBSquare (rank, file);
            }
开发者ID:BackupTheBerlios,项目名称:csboard-svn,代码行数:20,代码来源:CBSquare.cs

示例5: reverseWords

    // A1: going in reverse order, detect each word to append to the new string
    public String reverseWords(String a)
    {
        if (a == null || a.length() == 0) return a;

        StringBuilder b = new StringBuilder();

        int end = -1;
        int start = -1;
        int i = a.length()-1;

        while (i >= 0)
        {
            while (i >= 0 && a.charAt(i) == ' ') i--;
            end = i;

            while (i >= 0 && a.charAt(i) != ' ') i--;
            start = i;

            if (start < end) {
                if (b.length() > 0) b.append(' ');
                b.append(a.substring(start+1, end+1));
            }
        }

        return b.toString();
    }
开发者ID:hsn6,项目名称:training,代码行数:27,代码来源:FB_Revword.cs


注:本文中的String.charAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。