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


C# String.charAt方法代码示例

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


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

示例1: urlEncode

        public static String urlEncode(String fullPath)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int len = fullPath.length();

            char c;
            for (int index = 0; index < len; index++)
            {
                c = fullPath.charAt(index);
                if (c == '^' || c == '_'
                       || c == '\\' || c == '-'
                       || c == '.'
                       || (c >= 'A' && c <= 'Z')
                       || (c >= 'a' && c <= 'z')
                       || (c >= '0' && c <= '9'))
                {
                    sb.Append(c);
                }
                else
                {
                    sb.Append('%');
                    sb.Append(String.Format("{0:X2}", (int)c));
                }

            }
            return sb.ToString();
        }
开发者ID:arissetyawan,项目名称:rhodes,代码行数:27,代码来源:URI.cs

示例2: parseVerboseInt

 		private int parseVerboseInt(String input) {
 			String loadedString = String.format("%s", input);
 			boolean negative = false;
 			int base = 10;
 			int shift = 3;
 			int retVal = -1;
 			if (input.charAt(0) == '-') {
 				negative = true;
 				input = input.substring(1);
 			}
 			if (input.indexOf("0x") == 0) {
 				base = 16;
 				input = input.substring(2);
 			}
 			if (input.indexOf("b") == input.length() - 1) {
 				shift = 0;
 				input = input.substring(0, input.length() - 1);
 			}
 			try {
 				retVal = Integer.parseInt(input, base);
 			} catch (Exception e) {
 				addGeneralError(loadedString);
 				validComponent = false;
 			}
 			if (validComponent) {
 				retVal <<= shift;
 				if (negative)
 					retVal = 0 - retVal;
 			}
 			return retVal;
 		}
开发者ID:Crazycolorz5,项目名称:FEEditorSuite2015ProDeluxeEdition,代码行数:31,代码来源:NightmareModule.cs

示例3: asciiEndsWithIgnoreCase

 /**
  * Returns whether the given source string ends with the suffix, ignoring
  * case and assuming that the strings are ascii encoded.
  *
  * @param source
  *            the string to match.
  * @param suffix
  *            the suffix to test.
  * @return {@code true} if the source does end with the given suffix, or
  *         {@code false} if not.
  */
 public static bool asciiEndsWithIgnoreCase(String source, String suffix)
 {
     int length = suffix.length();
     if (length > source.length()) {
         return false;
     }
     int offset = source.length() - length;
     for (int i = 0; i < length; i++) {
         char c1 = source.charAt(i + offset);
         char c2 = suffix.charAt(i);
         if (c1 != c2 && toASCIIUpperCase(c1) != toASCIIUpperCase(c2)) {
             return false;
         }
     }
     return true;
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:27,代码来源:Util.cs

示例4: toASCIIUpperCase

 public static String toASCIIUpperCase(String s)
 {
     int len = s.length();
     StringBuilder buffer = new StringBuilder(len);
     for (int i = 0; i < len; i++)
     {
         char c = s.charAt(i);
         if ('a' <= c && c <= 'z')
         {
             buffer.append((char)(c - ('a' - 'A')));
         }
         else
         {
             buffer.append(c);
         }
     }
     return buffer.toString();
 }
开发者ID:gadfly,项目名称:nofs,代码行数:18,代码来源:org.apache.harmony.luni.util.Util.cs

示例5: parseNextCharacter

	    /**
	     * Parses <code>source</code> until a non-whitespace character is found.
	     *
	     * @param source the string to parse
	     * @param pos input/ouput parsing parameter.
	     * @return the first non-whitespace character.
	     */
	    public static char parseNextCharacter(String source,
	                                          ParsePosition pos) {
	         int index = pos.getIndex();
	         int n = source.length();
	         char ret = 0;
	
	         if (index < n) {
	             char c;
	             do {
	                 c = source.charAt(index++);
	             } while (Character.isWhitespace(c) && index < n);
	             pos.setIndex(index);
	
	             if (index < n) {
	                 ret = c;
	             }
	         }
	
	         return ret;
	    }
开发者ID:HankG,项目名称:Apache.Commons.Math,代码行数:27,代码来源:CompositeFormat.cs

示例6: quoteIllegal

        internal const String encoding = "utf-8"; //$NON-NLS-1$

        #endregion Fields

        #region Methods

        /**
         * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')
         * and legal characters are converted into their hexidecimal value prepended
         * by '%'.
         * <p>
         * For example: '#' -> %23
         * Other characters, which are unicode chars that are not US-ASCII, and are
         * not ISO Control or are not ISO Space chars, are preserved.
         * <p>
         * Called from {@code URI.quoteComponent()} (for multiple argument
         * constructors)
         *
         * @param s
         *            java.lang.String the string to be converted
         * @param legal
         *            java.lang.String the characters allowed to be preserved in the
         *            string s
         * @return java.lang.String the converted string
         */
        internal static String quoteIllegal(String s, String legal)
        {
            //throws UnsupportedEncodingException {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if ((ch >= 'a' && ch <= 'z')
                        || (ch >= 'A' && ch <= 'Z')
                        || (ch >= '0' && ch <= '9')
                        || legal.indexOf(ch) > -1
                        || (ch > 127 && !java.lang.Character.isSpaceChar(ch) && !java.lang.Character
                                .isISOControl(ch))) {
                    buf.append(ch);
                } else {
                    byte[] bytes = new String(new char[] { ch }).getBytes(encoding);
                    for (int j = 0; j < bytes.Length; j++) {
                        buf.append('%');
                        buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                        buf.append(digits.charAt(bytes[j] & 0xf));
                    }
                }
            }
            return buf.toString();
        }
开发者ID:gadfly,项目名称:nofs,代码行数:49,代码来源:java.net.URIEncoderDecoder.cs

示例7: countUTFBytes

 internal long countUTFBytes(String str)
 {
     int utfCount = 0, length = str.length();
     for (int i = 0; i < length; i++) {
         int charValue = str.charAt(i);
         if (charValue > 0 && charValue <= 127) {
             utfCount++;
         } else if (charValue <= 2047) {
             utfCount += 2;
         } else {
             utfCount += 3;
         }
     }
     return utfCount;
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:15,代码来源:DataOutputStream.cs

示例8: upToWithQuotes

 protected internal static bool upToWithQuotes(String s, ParsePosition position,
         java.lang.StringBuffer buffer, char stop, char start)
 {
     int index = position.getIndex(), length = s.length(), count = 1;
     bool quote = false;
     while (index < length) {
         char ch = s.charAt(index++);
         if (ch == '\'') {
             quote = !quote;
         }
         if (!quote) {
             if (ch == stop) {
                 count--;
             }
             if (count == 0) {
                 position.setIndex(index);
                 return true;
             }
             if (ch == start) {
                 count++;
             }
         }
         buffer.append(ch);
     }
     // text.07=Unmatched braces in the pattern
     throw new java.lang.IllegalArgumentException("Unmatched braces in the pattern"); //$NON-NLS-1$
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:27,代码来源:Format.cs

示例9: convertPattern

 protected internal virtual String convertPattern(String template, String fromChars, String toChars,
         bool check)
 {
     if (!check && fromChars.equals(toChars)) {
         return template;
     }
     bool quote = false;
     StringBuilder output = new StringBuilder();
     int length = template.length();
     for (int i = 0; i < length; i++) {
         int index;
         char next = template.charAt(i);
         if (next == '\'') {
             quote = !quote;
         }
         if (!quote && (index = fromChars.indexOf(next)) != -1) {
             output.append(toChars.charAt(index));
         } else if (check
                 && !quote
                 && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
             // text.05=Invalid pattern char {0} in {1}
             throw new java.lang.IllegalArgumentException("Invalid pattern char "+next+" in "+ template); //$NON-NLS-1$
         } else {
             output.append(next);
         }
     }
     if (quote) {
         // text.04=Unterminated quote
         throw new java.lang.IllegalArgumentException("Unterminated quote"); //$NON-NLS-1$
     }
     return output.toString();
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:32,代码来源:Format.cs

示例10: utf8Count

 static int utf8Count(String value)
 {
     int total = 0;
     for (int i = value.length(); --i >= 0;) {
         char ch = value.charAt(i);
         if (ch < 0x80) {
             total++;
         } else if (ch < 0x800) {
             total += 2;
         } else {
             total += 3;
         }
     }
     return total;
 }
开发者ID:gadfly,项目名称:nofs,代码行数:15,代码来源:java.util.zip.ZipOutputStream.cs

示例11: getInternalField

 /*
  * Gets private field value by reflection.
  *
  * @param fieldName the field name to be set @param target the object which
  * field to be gotten
  *
 internal static Object getInternalField(String fieldName, Object target) {
     Object value = AccessController
             .doPrivileged(new PrivilegedAction<Object>() {
                 public Object run() {
                     Object result = null;
                     java.lang.reflect.Field field = null;
                     try {
                         field = target.getClass().getDeclaredField(
                                 fieldName);
                         field.setAccessible(true);
                         result = field.get(target);
                     } catch (Exception e1) {
                         return null;
                     }
                     return result;
                 }
             });
     return value;
 }*/
 protected internal static bool upTo(String s, ParsePosition position,
         java.lang.StringBuffer buffer, char stop)
 {
     int index = position.getIndex(), length = s.length();
     bool lastQuote = false, quote = false;
     while (index < length) {
         char ch = s.charAt(index++);
         if (ch == '\'') {
             if (lastQuote) {
                 buffer.append('\'');
             }
             quote = !quote;
             lastQuote = true;
         } else if (ch == stop && !quote) {
             position.setIndex(index);
             return true;
         } else {
             lastQuote = false;
             buffer.append(ch);
         }
     }
     position.setIndex(index);
     return false;
 }
开发者ID:sailesh341,项目名称:JavApi,代码行数:49,代码来源:Format.cs

示例12: valueOf

        /**
         * &lt;p&gt;&lt;code&gt;QName&lt;/code&gt; derived from parsing the formatted
         * &lt;code&gt;String&lt;/code&gt;.&lt;/p&gt;
         *
         * &lt;p&gt;If the &lt;code&gt;String&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt; or does not conform to
         * {@link #toString() QName.toString()} formatting, an
         * &lt;code&gt;IllegalArgumentException&lt;/code&gt; is thrown.&lt;/p&gt;
         *
         * &lt;p&gt;&lt;em&gt;The &lt;code&gt;String&lt;/code&gt; &lt;strong&gt;MUST&lt;/strong&gt; be in the
         * form returned by {@link #toString() QName.toString()}.&lt;/em&gt;&lt;/p&gt;

         * &lt;p&gt;The commonly accepted way of representing a &lt;code&gt;QName&lt;/code&gt;
         * as a &lt;code&gt;String&lt;/code&gt; was &lt;a href="http://jclark.com/xml/xmlns.htm"&gt;defined&lt;/a&gt;
         * by James Clark.  Although this is not a &lt;em&gt;standard&lt;/em&gt;
         * specification, it is in common use,  e.g. {@link javax.xml.transform.Transformer#setParameter(String name, Object value)}.
         * This implementation parses a &lt;code&gt;String&lt;/code&gt; formatted
         * as: "{" + Namespace URI + "}" + local part.  If the Namespace
         * URI &lt;code&gt;.equals(XMLConstants.NULL_NS_URI)&lt;/code&gt;, only the
         * local part should be provided.&lt;/p&gt;
         *
         * &lt;p&gt;The prefix value &lt;strong&gt;&lt;em&gt;CANNOT&lt;/em&gt;&lt;/strong&gt; be
         * represented in the &lt;code&gt;String&lt;/code&gt; and will be set to
         * {@link javax.xml.XMLConstants#DEFAULT_NS_PREFIX
         * XMLConstants.DEFAULT_NS_PREFIX}.&lt;/p&gt;
         *
         * &lt;p&gt;This method does not do full validation of the resulting
         * &lt;code&gt;QName&lt;/code&gt;.
         * &lt;p&gt;The Namespace URI is not validated as a
         * &lt;a href="http://www.ietf.org/rfc/rfc2396.txt"&gt;URI reference&lt;/a&gt;.
         * The local part is not validated as a
         * &lt;a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName"&gt;NCName&lt;/a&gt;
         * as specified in
         * &lt;a href="http://www.w3.org/TR/REC-xml-names/"&gt;Namespaces in XML&lt;/a&gt;.&lt;/p&gt;
         *
         * @param qNameAsString &lt;code&gt;String&lt;/code&gt; representation
         * of the &lt;code&gt;QName&lt;/code&gt;
         * @return &lt;code&gt;QName&lt;/code&gt; corresponding to the given &lt;code&gt;String&lt;/code&gt;
         * @see #toString() QName.toString()
         */
        public static QName valueOf(String qNameAsString)
        {
            // null is not valid
            if (qNameAsString == null)
            {
                throw new java.lang.IllegalArgumentException("cannot create QName from \"null\" or \"\" String");
            }

            // "" local part is valid to preserve compatible behavior with QName 1.0
            if (qNameAsString.length() == 0)
            {
                return new QName(
                    XMLConstants.NULL_NS_URI,
                    qNameAsString,
                    XMLConstants.DEFAULT_NS_PREFIX);
            }

            // local part only?
            if (qNameAsString.charAt(0) != '{')
            {
                return new QName(
                    XMLConstants.NULL_NS_URI,
                    qNameAsString,
                    XMLConstants.DEFAULT_NS_PREFIX);
            }

            // Namespace URI improperly specified?
            if (qNameAsString.startsWith("{" + XMLConstants.NULL_NS_URI + "}"))
            {
                throw new java.lang.IllegalArgumentException(
                    "Namespace URI .equals(XMLConstants.NULL_NS_URI), "
                    + ".equals(\"" + XMLConstants.NULL_NS_URI + "\"), "
                    + "only the local part, "
                    + "\"" + qNameAsString.substring(2 + XMLConstants.NULL_NS_URI.length()) + "\", "
                    + "should be provided.");
            }

            // Namespace URI and local part specified
            int endOfNamespaceURI = qNameAsString.indexOf('}');
            if (endOfNamespaceURI == -1)
            {
                throw new java.lang.IllegalArgumentException(
                    "cannot create QName from \""
                        + qNameAsString
                        + "\", missing closing \"}\"");
            }
            return new QName(
                qNameAsString.substring(1, endOfNamespaceURI),
                qNameAsString.substring(endOfNamespaceURI + 1),
                XMLConstants.DEFAULT_NS_PREFIX);
        }
开发者ID:sailesh341,项目名称:JavApi,代码行数:90,代码来源:QName.cs

示例13: lastIndexOf

 /**
  * Searches for the index of the specified character. The search for the
  * character starts at the specified offset and moves towards the beginning.
  *
  * @param subString
  *            the string to find.
  * @param start
  *            the starting offset.
  * @return the index of the specified character, -1 if the character isn't
  *         found.
  * @throws NullPointerException
  *             if {@code subString} is {@code null}.
  * @see String#lastIndexOf(String,int)
  * @since 1.4
  */
 public virtual int lastIndexOf(String subString, int start)
 {
     int subCount = subString.length();
     if (subCount <= count && start >= 0) {
         if (subCount > 0) {
             if (start > count - subCount) {
                 start = count - subCount; // count and subCount are both
             }
             // >= 1
             // TODO optimize charAt to direct array access
             char firstChar = subString.charAt(0);
             while (true) {
                 int i = start;
                 bool found = false;
                 for (; i >= 0; --i) {
                     if (value[i] == firstChar) {
                         found = true;
                         break;
                     }
                 }
                 if (!found) {
                     return -1;
                 }
                 int o1 = i, o2 = 0;
                 while (++o2 < subCount
                         && value[++o1] == subString.charAt(o2)) {
                     // Intentionally empty
                 }
                 if (o2 == subCount) {
                     return i;
                 }
                 start = i - 1;
             }
         }
         return start < count ? start : count;
     }
     return -1;
 }
开发者ID:gadfly,项目名称:nofs,代码行数:53,代码来源:java.lang.AbstractStringBuilder.cs

示例14: encodeOthers

 /**
  * Other characters, which are Unicode chars that are not US-ASCII, and are
  * not ISO Control or are not ISO Space chars are not preserved. They are
  * converted into their hexidecimal value prepended by '%'.
  * <p>
  * For example: Euro currency symbol -> "%E2%82%AC".
  * <p>
  * Called from URI.toASCIIString()
  *
  * @param s
  *            java.lang.String the string to be converted
  * @return java.lang.String the converted string
  */
 static String encodeOthers(String s)
 {
     //throws UnsupportedEncodingException {
     StringBuilder buf = new StringBuilder();
     for (int i = 0; i < s.length(); i++) {
         char ch = s.charAt(i);
         if (ch <= 127) {
             buf.append(ch);
         } else {
             byte[] bytes = new String(new char[] { ch }).getBytes(encoding);
             for (int j = 0; j < bytes.Length; j++) {
                 buf.append('%');
                 buf.append(digits.charAt((bytes[j] & 0xf0) >> 4));
                 buf.append(digits.charAt(bytes[j] & 0xf));
             }
         }
     }
     return buf.toString();
 }
开发者ID:gadfly,项目名称:nofs,代码行数:32,代码来源:java.net.URIEncoderDecoder.cs

示例15: URL

        /**
         * Creates a new URL instance using the given arguments. The URL uses the
         * specified port instead of the default port for the given protocol.
         *
         * @param protocol
         *            the protocol of the new URL.
         * @param host
         *            the host name or IP address of the new URL.
         * @param port
         *            the specific port number of the URL. {@code -1} represents the
         *            default port of the protocol.
         * @param file
         *            the name of the resource.
         * @param handler
         *            the stream handler to be used by this URL.
         * @throws MalformedURLException
         *             if the combination of all arguments do not represent a valid
         *             URL or the protocol is invalid.
         * @throws SecurityException
         *             if {@code handler} is non-{@code null}, and a security
         *             manager is installed that disallows user-defined protocol
         *             handlers.
         */
        public URL(String protocol, String host, int port, String file,
                URLStreamHandler handler)
        {
            // throws MalformedURLException {
            if (port < -1)
            {
                throw new MalformedURLException("Port out of range: " + port); //$NON-NLS-1$
            }

            if (host != null && host.indexOf(":") != -1 && host.charAt(0) != '[')
            { //$NON-NLS-1$
                host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$
            }

            if (protocol == null)
            {
                throw new java.lang.NullPointerException("Unknown protocol: " + "null"); //$NON-NLS-1$ //$NON-NLS-2$
            }

            this.protocol = protocol;
            this.host = host;
            this.port = port;

            // Set the fields from the arguments. Handle the case where the
            // passed in "file" includes both a file and a reference part.
            int index = -1;
            index = file.indexOf("#", file.lastIndexOf("/")); //$NON-NLS-1$ //$NON-NLS-2$
            if (index >= 0)
            {
                this.file = file.substring(0, index);
                refJ = file.substring(index + 1);
            }
            else
            {
                this.file = file;
            }
            fixURL(false);

            // Set the stream handler for the URL either to the handler
            // argument if it was specified, or to the default for the
            // receiver's protocol if the handler was null.
            if (handler == null)
            {
                setupStreamHandler();
                if (strmHandler == null)
                {
                    throw new MalformedURLException("Unknown protocol: " + protocol); //$NON-NLS-1$
                }
            }
            else
            {
                java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager();
                if (sm != null)
                {
                    sm.checkPermission(specifyStreamHandlerPermission);
                }
                strmHandler = handler;
            }
        }
开发者ID:sailesh341,项目名称:JavApi,代码行数:82,代码来源:URL.cs


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