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


C# String.CharAt方法代码示例

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


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

示例1: isBasicallyValidEmailAddress

 /// <summary> This implements only the most basic checking for an email address's validity -- that it contains
 /// an '@' contains no characters disallowed by RFC 2822. This is an overly lenient definition of
 /// validity. We want to generally be lenient here since this class is only intended to encapsulate what's
 /// in a barcode, not "judge" it.
 /// </summary>
 internal static bool isBasicallyValidEmailAddress(String email)
 {
     if (email == null)
     {
         return false;
     }
     bool atFound = false;
     for (int i = 0; i < email.Length; i++)
     {
         char c = email.CharAt(i);
         if ((CharExtend.ToInt32(c) < CharExtend.ToInt32('a') || CharExtend.ToInt32(c) > CharExtend.ToInt32('z')) &&
             (CharExtend.ToInt32(c) < CharExtend.ToInt32('A') || CharExtend.ToInt32(c) > CharExtend.ToInt32('Z')) &&
             (CharExtend.ToInt32(c) < CharExtend.ToInt32('0') || CharExtend.ToInt32(c) > CharExtend.ToInt32('9')) &&
             !isAtextSymbol(c))
         {
             return false;
         }
         if (c == '@')
         {
             if (atFound)
             {
                 return false;
             }
             atFound = true;
         }
     }
     return atFound;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:33,代码来源:EmailDoCoMoResultParser.cs

示例2: GetCharsFromString

 /*******************************/
 /// <summary>
 /// Copies an array of chars obtained from a String into a specified array of chars
 /// </summary>
 /// <param name="sourceString">The String to get the chars from</param>
 /// <param name="sourceStart">Position of the String to start getting the chars</param>
 /// <param name="sourceEnd">Position of the String to end getting the chars</param>
 /// <param name="destinationArray">Array to return the chars</param>
 /// <param name="destinationStart">Position of the destination array of chars to start storing the chars</param>
 /// <returns>An array of chars</returns>
 public static void GetCharsFromString(String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
 {
     int sourceCounter;
     int destinationCounter;
     sourceCounter = sourceStart;
     destinationCounter = destinationStart;
     while (sourceCounter < sourceEnd)
     {
         destinationArray[destinationCounter] = (char) sourceString.CharAt(sourceCounter);
         sourceCounter++;
         destinationCounter++;
     }
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:23,代码来源:SupportClass.cs

示例3: unescapeBackslash

 protected internal static String unescapeBackslash(String escaped)
 {
     if (escaped != null)
     {
         int backslash = escaped.IndexOf('\\');
         if (backslash >= 0)
         {
             int max = escaped.Length;
             StringBuilder unescaped = new StringBuilder();
             unescaped.Append(escaped.Substr(0, backslash));
             bool nextIsEscaped = false;
             for (int i = backslash; i < max; i++)
             {
                 char c = escaped.CharAt(i);
                 if (nextIsEscaped || c != '\\')
                 {
                     unescaped.Append(c);
                     nextIsEscaped = false;
                 }
                 else
                 {
                     nextIsEscaped = true;
                 }
             }
             return unescaped.ToString();
         }
     }
     return escaped;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:29,代码来源:ResultParser.cs

示例4: matchPrefixedField

 internal static String[] matchPrefixedField(String prefix, String rawText, char endChar, bool trim)
 {
     ArrayList matches = null;
     int i = 0;
     int max = rawText.Length;
     while (i < max)
     {
         //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
         i = rawText.IndexOf(prefix, i);
         if (i < 0)
         {
             break;
         }
         i += prefix.Length; // Skip past this prefix we found to start
         int start = i; // Found the start of a match here
         bool done = false;
         while (!done)
         {
             //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
             i = rawText.IndexOf((Char) endChar, i);
             if (i < 0)
             {
                 // No terminating end character? uh, done. Set i such that loop terminates and break
                 i = rawText.Length;
                 done = true;
             }
             else if (rawText.CharAt(i - 1) == '\\')
             {
                 // semicolon was escaped so continue
                 i++;
             }
             else
             {
                 // found a match
                 if (matches == null)
                 {
                     matches = new ArrayList(); // lazy init
                 }
                 String element = unescapeBackslash(rawText.Substr(start, (i) - (start)));
                 if (trim)
                 {
                     element = element.Trim();
                 }
                 matches.Add(element);
                 i++;
                 done = true;
             }
         }
     }
     if (matches == null || (matches.Count == 0))
     {
         return null;
     }
     return toStringArray(matches);
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:55,代码来源:ResultParser.cs

示例5: isSubstringOfDigits

 protected internal static bool isSubstringOfDigits(String value_Renamed, int offset, int length)
 {
     if (value_Renamed == null)
     {
         return false;
     }
     int stringLength = value_Renamed.Length;
     int max = offset + length;
     if (stringLength < max)
     {
         return false;
     }
     for (int i = offset; i < max; i++)
     {
         char c = value_Renamed.CharAt(i);
         if (CharExtend.ToInt32(c) < CharExtend.ToInt32('0') || CharExtend.ToInt32(c) > CharExtend.ToInt32('9'))
         {
             return false;
         }
     }
     return true;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:22,代码来源:ResultParser.cs

示例6: isStringOfDigits

 protected internal static bool isStringOfDigits(String value_Renamed, int length)
 {
     if (value_Renamed == null)
     {
         return false;
     }
     int stringLength = value_Renamed.Length;
     if (length != stringLength)
     {
         return false;
     }
     for (int i = 0; i < length; i++)
     {
         char c = value_Renamed.CharAt(i);
         if (CharExtend.ToInt32(c) < CharExtend.ToInt32('0') || CharExtend.ToInt32(c) > CharExtend.ToInt32('9'))
         {
             return false;
         }
     }
     return true;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:21,代码来源:ResultParser.cs

示例7: formatAddress

 private static String formatAddress(String address)
 {
     if (address == null)
     {
         return null;
     }
     int length = address.Length;
     StringBuilder newAddress = new StringBuilder();
     for (int j = 0; j < length; j++)
     {
         char c = address.CharAt(j);
         if (c == ';')
         {
             newAddress.Append(' ');
         }
         else
         {
             newAddress.Append(c);
         }
     }
     return newAddress.ToString().Trim();
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:22,代码来源:VCardResultParser.cs

示例8: matchVCardPrefixedField

 private static String[] matchVCardPrefixedField(String prefix, String rawText, bool trim)
 {
     ArrayList matches = null;
     int i = 0;
     int max = rawText.Length;
     while (i < max)
     {
         //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
         i = rawText.IndexOf(prefix, i);
         if (i < 0)
         {
             break;
         }
         if (i > 0 && rawText.CharAt(i - 1) != '\n')
         {
             // then this didn't start a new token, we matched in the middle of something
             i++;
             continue;
         }
         i += prefix.Length; // Skip past this prefix we found to start
         if (rawText.CharAt(i) != ':' && rawText.CharAt(i) != ';')
         {
             continue;
         }
         while (rawText.CharAt(i) != ':')
         {
             // Skip until a colon
             i++;
         }
         i++; // skip colon
         int start = i; // Found the start of a match here
         //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
         i = rawText.IndexOf('\n', i); // Really, ends in \r\n
         if (i < 0)
         {
             // No terminating end character? uh, done. Set i such that loop terminates and break
             i = max;
         }
         else if (i > start)
         {
             // found a match
             if (matches == null)
             {
                 matches = new ArrayList(); // lazy init
             }
             String element = rawText.Substr(start, (i) - (start));
             if (trim)
             {
                 element = element.Trim();
             }
             matches.Add(element);
             i++;
         }
         else
         {
             i++;
         }
     }
     if (matches == null || (matches.Count == 0))
     {
         return null;
     }
     return toStringArray(matches);
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:64,代码来源:VCardResultParser.cs

示例9: isLikeVCardDate

 private static bool isLikeVCardDate(String value_Renamed)
 {
     if (value_Renamed == null)
     {
         return true;
     }
     // Not really sure this is true but matches practice
     // Mach YYYYMMDD
     if (isStringOfDigits(value_Renamed, 8))
     {
         return true;
     }
     // or YYYY-MM-DD
     return value_Renamed.Length == 10 && value_Renamed.CharAt(4) == '-' && value_Renamed.CharAt(7) == '-' && isSubstringOfDigits(value_Renamed, 0, 4) && isSubstringOfDigits(value_Renamed, 5, 2) && isSubstringOfDigits(value_Renamed, 8, 2);
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:15,代码来源:VCardResultParser.cs

示例10: chooseMode2

 /// <summary> Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 /// if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 /// </summary>
 public static Mode chooseMode2(String content, String encoding)
 {
     if ("Shift_JIS" == encoding)
     {
         // Choose Kanji mode if all input are double-byte characters
         return isOnlyDoubleByteKanji(content)?Mode.KANJI:Mode.BYTE;
     }
     bool hasNumeric = false;
     bool hasAlphanumeric = false;
     for (int i = 0; i < content.Length; ++i)
     {
         char c = content.CharAt(i);
         if (CharExtend.ToInt32(c) >= CharExtend.ToInt32('0') && CharExtend.ToInt32(c) <= CharExtend.ToInt32('9'))
         {
             hasNumeric = true;
         }
         else if (getAlphanumericCode(CharExtend.ToInt32(c)) != - 1)
         {
             hasAlphanumeric = true;
         }
         else
         {
             return Mode.BYTE;
         }
     }
     if (hasAlphanumeric)
     {
         return Mode.ALPHANUMERIC;
     }
     else if (hasNumeric)
     {
         return Mode.NUMERIC;
     }
     return Mode.BYTE;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:38,代码来源:Encoder.cs

示例11: isColonFollowedByPortNumber

 private static bool isColonFollowedByPortNumber(String uri, int protocolEnd)
 {
     //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
     int nextSlash = uri.IndexOf('/', protocolEnd + 1);
     if (nextSlash < 0)
     {
         nextSlash = uri.Length;
     }
     if (nextSlash <= protocolEnd + 1)
     {
         return false;
     }
     for (int x = protocolEnd + 1; x < nextSlash; x++)
     {
         if (uri.CharAt(x) < '0' || uri.CharAt(x) > '9')
         {
             return false;
         }
     }
     return true;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:21,代码来源:URIParsedResult.cs

示例12: isBasicallyValidURI

 /// <summary> Determines whether a string is not obviously not a URI. This implements crude checks; this class does not
 /// intend to strictly check URIs as its only function is to represent what is in a barcode, but, it does
 /// need to know when a string is obviously not a URI.
 /// </summary>
 internal static bool isBasicallyValidURI(String uri)
 {
     if (uri == null || uri.IndexOf(' ') >= 0 || uri.IndexOf('\n') >= 0)
     {
         return false;
     }
     // Look for period in a domain but followed by at least a two-char TLD
     // Forget strings that don't have a valid-looking protocol
     int period = uri.IndexOf('.');
     if (period >= uri.Length - 2)
     {
         return false;
     }
     int colon = uri.IndexOf(':');
     if (period < 0 && colon < 0)
     {
         return false;
     }
     if (colon >= 0)
     {
         if (period < 0 || period > colon)
         {
             // colon ends the protocol
             for (int i = 0; i < colon; i++)
             {
                 char c = uri.CharAt(i);
                 if ((CharExtend.ToInt32(c) < CharExtend.ToInt32('a') || CharExtend.ToInt32(c) > CharExtend.ToInt32('z')) && (CharExtend.ToInt32(c) < CharExtend.ToInt32('A') || CharExtend.ToInt32(c) > CharExtend.ToInt32('Z')))
                 {
                     return false;
                 }
             }
         }
         else
         {
             // colon starts the port; crudely look for at least two numbers
             if (colon >= uri.Length - 2)
             {
                 return false;
             }
             for (int i = colon + 1; i < colon + 3; i++)
             {
                 char c = uri.CharAt(i);
                 if (CharExtend.ToInt32(c) < CharExtend.ToInt32('0') || CharExtend.ToInt32(c) > CharExtend.ToInt32('9'))
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:55,代码来源:URIResultParser.cs

示例13: validateDate

 /// <summary> RFC 2445 allows the start and end fields to be of type DATE (e.g. 20081021) or DATE-TIME
 /// (e.g. 20081021T123000 for local time, or 20081021T123000Z for UTC).
 /// 
 /// </summary>
 /// <param name="date">The string to validate
 /// </param>
 private static void validateDate(String date)
 {
     if (date != null)
     {
         int length = date.Length;
         if (length != 8 && length != 15 && length != 16)
         {
             throw new Exception("ArgumentException");
         }
         for (int i = 0; i < 8; i++)
         {
             if (!CharExtend.IsDigit(date.CharAt(i)))
             {
                 throw new Exception("ArgumentException");
             }
         }
         if (length > 8)
         {
             if (date.CharAt(8) != 'T')
             {
                 throw new Exception("ArgumentException");
             }
             for (int i = 9; i < 15; i++)
             {
                 if (!CharExtend.IsDigit(date.CharAt(i)))
                 {
                     throw new Exception("ArgumentException");
                 }
             }
             if (length == 16 && date.CharAt(15) != 'Z')
             {
                 throw new Exception("ArgumentException");
             }
         }
     }
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:42,代码来源:CalendarParsedResult.cs

示例14: convertUPCEtoUPCA

        /// <summary> Expands a UPC-E value back into its full, equivalent UPC-A code value.
        /// 
        /// </summary>
        /// <param name="upce">UPC-E code as string of digits
        /// </param>
        /// <returns> equivalent UPC-A code as string of digits
        /// </returns>
        public static String convertUPCEtoUPCA(String upce)
        {
            char[] upceChars = new char[6];
            SupportClass.GetCharsFromString(upce, 1, 7, upceChars, 0);
            StringBuilder result = new StringBuilder();
            result.Append(upce.CharAt(0));
            char lastChar = upceChars[5];
            switch (lastChar)
            {

                case '0':
                case '1':
                case '2':
                    result.Append(upceChars.Extract(0, 2).Join());
                    result.Append(lastChar);
                    result.Append("0000");
                    result.Append(upceChars.Extract(2, 3).Join());
                    break;

                case '3':
                    result.Append(upceChars.Extract(0, 3).Join());
                    result.Append("00000");
                    result.Append(upceChars.Extract(3, 2).Join());
                    break;

                case '4':
                    result.Append(upceChars.Extract(0, 4).Join());
                    result.Append("00000");
                    result.Append(upceChars[4]);
                    break;

                default:
                    result.Append(upceChars.Extract(0, 5).Join());
                    result.Append("0000");
                    result.Append(lastChar);
                    break;

            }
            result.Append(upce.CharAt(7));
            return result.ToString();
        }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:48,代码来源:UPCEReader.cs

示例15: add

        /// <summary> Add two numbers which are represented as strings.
        /// 
        /// </summary>
        /// <param name="value1">
        /// </param>
        /// <param name="value2">
        /// </param>
        /// <returns> the result of value1 + value2
        /// </returns>
        private static StringBuilder add(String value1, String value2)
        {
            StringBuilder temp1 = new StringBuilder();
            StringBuilder temp2 = new StringBuilder();
            //System.StringBuilder result = new System.StringBuilder();
            char[] result = new char[value1.Length];
            for (int i = 0; i < value1.Length; i++)
            {
                // Put zeros into the result.
                result[i] = '0';
            }
            int carry = 0;
            for (int i = value1.Length - 3; i > - 1; i -= 3)
            {

                temp1.Clear();
                temp1.Append(value1.CharAt(i));
                temp1.Append(value1.CharAt(i + 1));
                temp1.Append(value1.CharAt(i + 2));

                temp2.Clear();
                temp2.Append(value2.CharAt(i));
                temp2.Append(value2.CharAt(i + 1));
                temp2.Append(value2.CharAt(i + 2));

                int intValue1 = Int32.Parse(temp1.ToString());
                int intValue2 = Int32.Parse(temp2.ToString());

                int sumval = (intValue1 + intValue2 + carry) % 1000;
                carry = Math.Floor((intValue1 + intValue2 + carry) / 1000);

                result[i + 2] = Int32Extend.ToChar((sumval % 10) + CharExtend.ToInt32('0'));
                result[i + 1] = Int32Extend.ToChar((Math.Floor(sumval / 10) % 10) + CharExtend.ToInt32('0'));
                result[i] = Int32Extend.ToChar(Math.Floor(sumval / 100) + CharExtend.ToInt32('0'));
            }
            return new StringBuilder(result.Join());
        }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:46,代码来源:DecodedBitStreamParser.cs


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