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


C# String.Substr方法代码示例

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


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

示例1: UnescapeString

        public static String UnescapeString(String Value)
        {
            if (Value.Length < 2) throw(new Exception("Invalid String [1]"));
            if (Value[0] != '\'' && Value[0] != '"') throw (new Exception("Invalid String [2]"));
            if (Value.Substr(0, 1) != Value.Substr(-1, 1)) throw (new Exception("Invalid String [3]"));
            String RetString = "";
            Value = Value.Substr(1, -1);
            for (int n = 0; n < Value.Length; n++)
            {
                if (Value[n] == '\\')
                {
                    switch (Value[++n])
                    {
                        case 'n': RetString += '\n'; break;
                        case 'r': RetString += '\r'; break;
                        case 't': RetString += '\t'; break;
                        default: throw(new Exception("Unknown Escape Sequence"));
                    }
                }
                else
                {
                    RetString += Value[n];
                }
            }

            return RetString;
        }
开发者ID:yash0924,项目名称:csharputils,代码行数:27,代码来源:StringUtils.cs

示例2: encode2

        /// <returns> a byte array of horizontal pixels (0 = white, 1 = black) 
        /// </returns>
        public override sbyte[] encode2(String contents)
        {
            if (contents.Length != 8)
            {
                throw new Exception("ArgumentException: Requested contents should be 8 digits long, but got " + contents.Length);
            }

            sbyte[] result = new sbyte[codeWidth];
            int pos = 0;

            pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);

            for (int i = 0; i <= 3; i++)
            {
                int digit = Int32.Parse(contents.Substr(i, (i + 1) - (i)));
                pos += appendPattern(result, pos, UPCEANReader.L_PATTERNS[digit], 0);
            }

            pos += appendPattern(result, pos, UPCEANReader.MIDDLE_PATTERN, 0);

            for (int i = 4; i <= 7; i++)
            {
                int digit = Int32.Parse(contents.Substr(i, (i + 1) - (i)));
                pos += appendPattern(result, pos, UPCEANReader.L_PATTERNS[digit], 1);
            }
            pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);

            return result;
        }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:31,代码来源:EAN8Writer.cs

示例3: ParseIntegerConstant

		public static int ParseIntegerConstant(String Value, int DefaultBase = 10)
		{
			try
			{
				Value = Value.Replace("_", "");
				if (Value.Substr(0, 1) == "-") return -ParseIntegerConstant(Value.Substr(1));
				if (Value.Substr(0, 1) == "+") return +ParseIntegerConstant(Value.Substr(1));
				if (Value.Substr(0, 2) == "0x") return Convert.ToInt32(Value.Substr(2), 16);
				if (Value.Substr(0, 2) == "0b") return Convert.ToInt32(Value.Substr(2), 2);
				return Convert.ToInt32(Value, DefaultBase);
			}
			catch (FormatException FormatException)
			{
				throw (new FormatException("Can't parse the string '" + Value + "'", FormatException));
			}
		}
开发者ID:shin527,项目名称:cspspemu,代码行数:16,代码来源:NumberUtils.cs

示例4: encode2

        public override sbyte[] encode2(String contents)
        {
            if (contents.Length != 13)
            {
                throw new Exception("ArgumentException: Requested contents should be 13 digits long, but got " + contents.Length);
            }

            int firstDigit = Int32.Parse(contents.Substr(0, (1) - (0)));
            int parities = EAN13Reader.FIRST_DIGIT_ENCODINGS[firstDigit];
            sbyte[] result = new sbyte[codeWidth];
            int pos = 0;

            pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);

            // See {@link #EAN13Reader} for a description of how the first digit & left bars are encoded
            for (int i = 1; i <= 6; i++)
            {
                int digit = Int32.Parse(contents.Substr(i, (i + 1) - (i)));
                if ((parities >> (6 - i) & 1) == 1)
                {
                    digit += 10;
                }
                pos += appendPattern(result, pos, UPCEANReader.L_AND_G_PATTERNS[digit], 0);
            }

            pos += appendPattern(result, pos, UPCEANReader.MIDDLE_PATTERN, 0);

            for (int i = 7; i <= 12; i++)
            {
                int digit = Int32.Parse(contents.Substr(i, (i + 1) - (i)));
                pos += appendPattern(result, pos, UPCEANReader.L_PATTERNS[digit], 1);
            }
            pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);

            return result;
        }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:36,代码来源:EAN13Writer.cs

示例5: TokenizeRegex

 /*
 static public IEnumerable<String> TokenizeRegex(String Line)
 {
     var Matches = new Regex(@"(\+\d+|-\d+|[%\w]+|\S)", RegexOptions.Compiled).Matches(Line);
     var Ret = new String[Matches.Count];
     for (int n = 0; n < Matches.Count; n++) Ret[n] = Matches[n].Value;
     return Ret;
 }
 */
 public static IEnumerable<String> TokenizeFast(String Line)
 {
     var Parts = new List<String>();
     for (int n = 0; n < Line.Length; n++)
     {
         if (IsIdent(Line[n]))
         {
             int m = n;
             for (; n < Line.Length && IsIdent(Line[n]); n++) { }
             Parts.Add(Line.Substr(m, n - m));
             n--;
         }
         else
         {
             if (!IsSpace(Line[n]))
             {
                 Parts.Add("" + Line[n]);
             }
         }
     }
     return Parts;
 }
开发者ID:mrcmunir,项目名称:cspspemu,代码行数:31,代码来源:MipsAssembler.cs

示例6: urlDecode

        private static String urlDecode(String escaped)
        {
            // No we can't use java.net.URLDecoder here. JavaME doesn't have it.
            if (escaped == null)
            {
                return null;
            }
            char[] escapedArray = StringExtend.ToCharArray(escaped);

            int first = findFirstEscape(escapedArray);
            if (first < 0)
            {
                return escaped;
            }

            int max = escapedArray.Length;
            // final length is at most 2 less than original due to at least 1 unescaping
            StringBuilder unescaped = new StringBuilder();
            // Can append everything up to first escape character
            unescaped.Append(escaped.Substr(0, first));

            for (int i = first; i < max; i++)
            {
                char c = escapedArray[i];
                if (c == '+')
                {
                    // + is translated directly into a space
                    unescaped.Append(' ');
                }
                else if (c == '%')
                {
                    // Are there even two more chars? if not we will just copy the escaped sequence and be done
                    if (i >= max - 2)
                    {
                        unescaped.Append('%'); // append that % and move on
                    }
                    else
                    {
                        int firstDigitValue = parseHexDigit(escapedArray[++i]);
                        int secondDigitValue = parseHexDigit(escapedArray[++i]);
                        if (firstDigitValue < 0 || secondDigitValue < 0)
                        {
                            // bad digit, just move on
                            unescaped.Append('%');
                            unescaped.Append(escapedArray[i - 1]);
                            unescaped.Append(escapedArray[i]);
                        }
                        unescaped.Append((char) ((firstDigitValue << 4) + secondDigitValue));
                    }
                }
                else
                {
                    unescaped.Append(c);
                }
            }
            return unescaped.ToString();
        }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:57,代码来源:ResultParser.cs

示例7: appendKeyValue

 private static void appendKeyValue(String uri, int paramStart, int paramEnd, Dictionary result)
 {
     //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 separator = uri.IndexOf('=', paramStart);
     if (separator >= 0)
     {
         // key = value
         String key = uri.Substr(paramStart, (separator) - (paramStart));
         String value_Renamed = uri.Substr(separator + 1, (paramEnd) - (separator + 1));
         value_Renamed = urlDecode(value_Renamed);
         result[key] = value_Renamed;
     }
     // Can't put key, null into a hashtable
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:14,代码来源:ResultParser.cs

示例8: 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

示例9: 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

示例10: 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

示例11: parseName

 private static String parseName(String name)
 {
     int comma = name.IndexOf(',');
     if (comma >= 0)
     {
         // Format may be last,first; switch it around
         return name.Substr(comma + 1) + ' ' + name.Substr(0, (comma) - (0));
     }
     return name;
 }
开发者ID:tomcat1234,项目名称:WebQRReader,代码行数:10,代码来源:AddressBookDoCoMoResultParser.cs


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