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


C# System.Substring方法代码示例

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


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

示例1: discover

	protected internal override void  discover(System.Type clazz, System.String propertyName) {
	    try {
		Introspector introspector = rsvc.Introspector;
		property = introspector.getProperty(clazz, propertyName);
		if (property != null) {
		    if (property.PropertyType.Equals(typeof(Boolean))) {
			return ;
		    }
		}

		/*
		*  now the convenience, flip the 1st character
		*/
		propertyName = propertyName.Substring(0,1).ToUpper() + propertyName.Substring(1);
		property = introspector.getProperty(clazz, propertyName);
		if (property != null)
		    if (property.PropertyType.Equals(typeof(Boolean))) {
			return ;
		    }

		property = null;
	    } catch (System.Exception e) {
		rsvc.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e);
	    }
	}
开发者ID:BackupTheBerlios,项目名称:ch3etah-svn,代码行数:25,代码来源:BooleanPropertyExecutor.cs

示例2: escape

		public static System.String escape(System.String text, NuGenEncodingCharacters encChars)
		{
			System.Text.StringBuilder result = new System.Text.StringBuilder();
			int textLength = text.Length;
			System.Collections.Hashtable esc = getEscapeSequences(encChars);
			SupportClass.SetSupport keys = new SupportClass.HashSetSupport(esc.Keys);
			System.String escChar = System.Convert.ToString(encChars.EscapeCharacter);
			int position = 0;
			while (position < textLength)
			{
				System.Collections.IEnumerator it = keys.GetEnumerator();
				bool isReplaced = false;
				while (it.MoveNext() && !isReplaced)
				{
					System.String seq = (System.String) it.Current;
					System.String val = (System.String) esc[seq];
					if (text.Substring(position, (position + 1) - (position)).Equals(val))
					{
						result.Append(seq);
						isReplaced = true;
					}
				}
				if (!isReplaced)
				{
					result.Append(text.Substring(position, ((position + 1)) - (position)));
				}
				position++;
			}
			return result.ToString();
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:30,代码来源:NuGenEscape.cs

示例3: SimpleMatch

 /// <summary> Match a String against the given pattern, supporting the following simple
 /// pattern styles: "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality.
 /// </summary>
 /// <param name="pattern">the pattern to match against
 /// </param>
 /// <param name="str">the String to match
 /// </param>
 /// <returns> whether the String matches the given pattern
 /// </returns>
 public static bool SimpleMatch(System.String pattern, System.String str)
 {
     if (ObjectUtils.NullSafeEquals(pattern, str) || "*".Equals(pattern))
     {
         return true;
     }
     if (pattern == null || str == null)
     {
         return false;
     }
     if (pattern.StartsWith("*") && pattern.EndsWith("*") &&
         str.IndexOf(pattern.Substring(1, (pattern.Length - 1) - (1))) != -1)
     {
         return true;
     }
     if (pattern.StartsWith("*") && str.EndsWith(pattern.Substring(1, (pattern.Length) - (1))))
     {
         return true;
     }
     if (pattern.EndsWith("*") && str.StartsWith(pattern.Substring(0, (pattern.Length - 1) - (0))))
     {
         return true;
     }
     return false;
 }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:34,代码来源:PatternMatchUtils.cs

示例4: Decode

		internal static System.String Decode(System.String entity)
		{
			if (entity[entity.Length - 1] == ';')
			// remove trailing semicolon
				entity = entity.Substring(0, (entity.Length - 1) - (0));
			if (entity[1] == '#')
			{
				int start = 2;
				int radix = 10;
				if (entity[2] == 'X' || entity[2] == 'x')
				{
					start++;
					radix = 16;
				}
				System.Char c = (char) System.Convert.ToInt32(entity.Substring(start), radix);
				return c.ToString();
			}
			else
			{
				System.String s = (System.String) decoder[entity];
				if (s != null)
					return s;
				else
					return "";
			}
		}
开发者ID:emtees,项目名称:old-code,代码行数:26,代码来源:Entities.cs

示例5: encode

        /// <returns> a byte array of horizontal pixels (0 = white, 1 = black) 
        /// </returns>
        public override sbyte[] encode(System.String contents)
        {
            if (contents.Length != 8)
            {
                throw new System.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 = System.Int32.Parse(contents.Substring(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 = System.Int32.Parse(contents.Substring(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:hankhongyi,项目名称:zxing_for_wp8,代码行数:31,代码来源:EAN8Writer.cs

示例6: parseName

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

示例7: Parse

 /// <summary>
 ///
 /// </summary>
 /// <param name="s"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static System.Single Parse(System.String s, System.Globalization.NumberStyles style)
 {
     if (s.EndsWith("f") || s.EndsWith("F"))
         return System.Single.Parse(s.Substring(0, s.Length - 1), style);
     else
         return System.Single.Parse(s, style);
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:Single.cs

示例8: Accept

		/* (non-Javadoc)
		* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
		*/
		public virtual bool Accept(System.IO.FileInfo dir, System.String name)
		{
			int i = name.LastIndexOf((System.Char) '.');
			if (i != - 1)
			{
				System.String extension = name.Substring(1 + i);
				if (extensions.Contains(extension))
				{
					return true;
				}
				else if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
				{
					return true;
				}
				else if (extension.StartsWith("s") && (new System.Text.RegularExpressions.Regex("s\\d+")).Match(extension).Success)
				{
					return true;
				}
			}
			else
			{
				if (name.Equals(IndexFileNames.DELETABLE))
					return true;
				else if (name.StartsWith(IndexFileNames.SEGMENTS))
					return true;
			}
			return false;
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:31,代码来源:IndexFileNameFilter.cs

示例9: getHL7Messages

		/// <summary> Given a string that contains HL7 messages, and possibly other junk, 
		/// returns an array of the HL7 messages.  
		/// An attempt is made to recognize segments even if there is other 
		/// content between segments, for example if a log file logs segments 
		/// individually with timestamps between them.  
		/// 
		/// </summary>
		/// <param name="theSource">a string containing HL7 messages 
		/// </param>
		/// <returns> the HL7 messages contained in theSource
		/// </returns>
        private static System.String[] getHL7Messages(System.String theSource)
        {
            System.Collections.ArrayList messages = new System.Collections.ArrayList(20);
            Match startMatch = new Regex("^MSH", RegexOptions.Multiline).Match(theSource);

            foreach (Group group in startMatch.Groups)
            {
                System.String messageExtent = getMessageExtent(theSource.Substring(group.Index), "^MSH");

                char fieldDelim = messageExtent[3];

                Match segmentMatch = Regex.Match(messageExtent, "^[A-Z]{3}\\" + fieldDelim + ".*$", RegexOptions.Multiline);

                System.Text.StringBuilder msg = new System.Text.StringBuilder();
                foreach (Group segGroup in segmentMatch.Groups)
                {
                    msg.Append(segGroup.Value.Trim());
                    msg.Append('\r');
                }

                messages.Add(msg.ToString());
            }

            String[] retVal = new String[messages.Count];
            messages.CopyTo(retVal);

            return retVal;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:39,代码来源:NuGenHl7InputStreamReader.cs

示例10: GradientFormatter

		/// <summary> Sets the color range for the IDF scores
		/// 
		/// </summary>
		/// <param name="">maxScore
		/// The score (and above) displayed as maxColor (See QueryScorer.getMaxWeight 
		/// which can be used to callibrate scoring scale)
		/// </param>
		/// <param name="">minForegroundColor
		/// The hex color used for representing IDF scores of zero eg
		/// #FFFFFF (white) or null if no foreground color required
		/// </param>
		/// <param name="">maxForegroundColor
		/// The largest hex color used for representing IDF scores eg
		/// #000000 (black) or null if no foreground color required
		/// </param>
		/// <param name="">minBackgroundColor
		/// The hex color used for representing IDF scores of zero eg
		/// #FFFFFF (white) or null if no background color required
		/// </param>
		/// <param name="">maxBackgroundColor
		/// The largest hex color used for representing IDF scores eg
		/// #000000 (black) or null if no background color required
		/// </param>
		public GradientFormatter(float maxScore, System.String minForegroundColor, System.String maxForegroundColor, System.String minBackgroundColor, System.String maxBackgroundColor)
		{
			highlightForeground = (minForegroundColor != null) && (maxForegroundColor != null);
			if (highlightForeground)
			{
				if (minForegroundColor.Length != 7)
				{
					throw new System.ArgumentException("minForegroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
				}
				if (maxForegroundColor.Length != 7)
				{
					throw new System.ArgumentException("minForegroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
				}
				fgRMin = HexToInt(minForegroundColor.Substring(1, (3) - (1)));
				fgGMin = HexToInt(minForegroundColor.Substring(3, (5) - (3)));
				fgBMin = HexToInt(minForegroundColor.Substring(5, (7) - (5)));
				
				fgRMax = HexToInt(maxForegroundColor.Substring(1, (3) - (1)));
				fgGMax = HexToInt(maxForegroundColor.Substring(3, (5) - (3)));
				fgBMax = HexToInt(maxForegroundColor.Substring(5, (7) - (5)));
			}
			
			highlightBackground = (minBackgroundColor != null) && (maxBackgroundColor != null);
			if (highlightBackground)
			{
				if (minBackgroundColor.Length != 7)
				{
					throw new System.ArgumentException("minBackgroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
				}
				if (maxBackgroundColor.Length != 7)
				{
					throw new System.ArgumentException("minBackgroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
				}
				bgRMin = HexToInt(minBackgroundColor.Substring(1, (3) - (1)));
				bgGMin = HexToInt(minBackgroundColor.Substring(3, (5) - (3)));
				bgBMin = HexToInt(minBackgroundColor.Substring(5, (7) - (5)));
				
				bgRMax = HexToInt(maxBackgroundColor.Substring(1, (3) - (1)));
				bgGMax = HexToInt(maxBackgroundColor.Substring(3, (5) - (3)));
				bgBMax = HexToInt(maxBackgroundColor.Substring(5, (7) - (5)));
			}
			//        this.corpusReader = corpusReader;
			this.maxScore = maxScore;
			//        totalNumDocs = corpusReader.numDocs();
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:68,代码来源:GradientFormatter.cs

示例11: GetExtension

 /// <summary>Utility method to return a file's extension. </summary>
 public static System.String GetExtension(System.String name)
 {
     int i = name.LastIndexOf('.');
     if (i == - 1)
     {
         return "";
     }
     return name.Substring(i + 1, (name.Length) - (i + 1));
 }
开发者ID:sinsay,项目名称:SSE,代码行数:10,代码来源:FileSwitchDirectory.cs

示例12: escape

        public static System.String escape(System.String text, EncodingCharacters encChars)
        {
            //First, take all special characters and replace them with something that is garbled
            for(int i=0;i<SPECIAL_ENCODING_VALUES.Length;i++)
            {
                string specialValues = SPECIAL_ENCODING_VALUES[i];
                text = text.Replace(specialValues, EncodeSpecialCharacters(i.ToString()));
            }
            //Encode each escape character
                        System.Collections.Hashtable esc = getEscapeSequences(encChars);
            System.Text.StringBuilder result = new System.Text.StringBuilder();
            SupportClass.SetSupport keys = new SupportClass.HashSetSupport(esc.Keys);
            System.String escChar = System.Convert.ToString(encChars.EscapeCharacter);
            int position = 0;
            while (position < text.Length)
            {
                System.Collections.IEnumerator it = keys.GetEnumerator();
                bool isReplaced = false;
                while (it.MoveNext() && !isReplaced)
                {
                    System.String seq = (System.String) it.Current;
                    System.String val = (System.String) esc[seq];
                    if (text.Substring(position, 1).Equals(val))
                    {
                        result.Append(seq);
                        isReplaced = true;
                    }
                }
                if (!isReplaced)
                {
                    result.Append(text.Substring(position, 1));
                }
                position++;
            }

            //Replace each garbled entry with the correct special value
            for(int i=0;i<SPECIAL_ENCODING_VALUES.Length;i++)
            {
                string specialValues = SPECIAL_ENCODING_VALUES[i];
                result.Replace(EncodeSpecialCharacters(i.ToString()), specialValues);
            }
            return result.ToString();
        }
开发者ID:snosrap,项目名称:nhapi,代码行数:43,代码来源:Escape.cs

示例13: standardizeER7

		/// <summary> Returns the shortest string that is semantically equivalent to a given ER7-encoded 
		/// message string.
		/// </summary>
		public static System.String standardizeER7(System.String message)
		{
			
			//make delimiter sequences (must quote with \ if not alphanumeric; can't otherwise because of regexp rules)
			char fieldDelimChar = message[3];
			System.String fieldDelim = System.Convert.ToString(fieldDelimChar);
			if (!System.Char.IsLetterOrDigit(fieldDelimChar))
				fieldDelim = "\\" + fieldDelimChar;
			
			char compSepChar = message[4];
			System.String compSep = System.Convert.ToString(compSepChar);
			if (!System.Char.IsLetterOrDigit(compSepChar))
				compSep = "\\" + compSepChar;
			
			char repSepChar = message[5];
			System.String repSep = System.Convert.ToString(repSepChar);
			if (!System.Char.IsLetterOrDigit(repSepChar))
				repSep = "\\" + repSepChar;
			
			char subSepChar = message[7];
			System.String subSep = System.Convert.ToString(subSepChar);
			if (!System.Char.IsLetterOrDigit(subSepChar))
				subSep = "\\" + subSepChar;
			
			//char space = ' ';
			
			/* Things to strip (cumulative):
			*  - all delimiters and repetition separators before end line (i.e. end segment)
			*  - repetition separators, comp and subcomp delims before new field
			*  - subcomponent delimiters before new component
			*/
            message = Regex.Replace(message, "[" + fieldDelim + compSep + repSep + subSep + "]*[\n\r]+", "\r");
            message = Regex.Replace(message, "[" + repSep + compSep + subSep + "]*" + fieldDelim, fieldDelim);
            message = Regex.Replace(message, "[" + subSep + "]*" + compSep, compSep);
			
			//Pattern endSub = Pattern.compile("[ ]*" + subSep);
			//message = endSub.matcher(message).replaceAll(String.valueOf(subSep));
			
			//handle special case of subcomp delim in encoding characters
			message = message.Substring(0, (7) - (0)) + subSepChar + message.Substring(7);
			
			return message;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:46,代码来源:NuGenEncodedMessageComparator.cs

示例14: RemoveTrailingBlanks

		/// <summary>
		/// 
		/// </summary>
		/// <param name="text"></param>
		/// <returns></returns>
		public static System.String RemoveTrailingBlanks(System.String text)
		{
			char ch = ' ';
			while (ch == ' ')
			{
				ch = text[text.Length - 1];
				if (ch == ' ')
					text = text.Substring(0, (text.Length - 1) - (0));
			}
			return text;
		}
开发者ID:JamalAbuDayyeh,项目名称:slowandsteadyparser,代码行数:16,代码来源:ParserUtils.cs

示例15: discover

	protected internal virtual void discover(System.Type clazz, System.String propertyName) {
	    /*
	    *  this is gross and linear, but it keeps it straightforward.
	    */

	    try {
		Introspector introspector = rsvc.Introspector;
		propertyUsed = propertyName;
		property = introspector.getProperty(clazz, propertyUsed);
		if (property != null) {
		    return ;
		}

		/*
		*  now the convenience, flip the 1st character
		*/
		propertyUsed = propertyName.Substring(0,1).ToUpper() + propertyName.Substring(1);
		property = introspector.getProperty(clazz, propertyUsed);
		if (property != null) {
		    return ;
		}

		propertyUsed = propertyName.Substring(0,1).ToLower() + propertyName.Substring(1);
		property = introspector.getProperty(clazz, propertyUsed);
		if (property != null) {
		    return ;
		}

		// check for a method that takes no arguments
		propertyUsed = propertyName;
		method = introspector.getMethod(clazz, propertyUsed, new Object[0]);
		if (method != null) {
		    return;
		}

		// check for a method that takes no arguments, flipping 1st character
		propertyUsed = propertyName.Substring(0,1).ToUpper() + propertyName.Substring(1);
		method = introspector.getMethod(clazz, propertyUsed, new Object[0]);
		if (method != null) {
		    return;
		}

		propertyUsed = propertyName.Substring(0,1).ToLower() + propertyName.Substring(1);
		method = introspector.getMethod(clazz, propertyUsed, new Object[0]);
		if (method != null) {
		    return;
		}
	    } catch (System.Exception e) {
		rsvc.error("PROGRAMMER ERROR : PropertyExector() : " + e);
	    }
	}
开发者ID:DF-thangld,项目名称:web_game,代码行数:51,代码来源:PropertyExecutor.cs


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