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


C# String.Substring方法代码示例

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


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

示例1: ConvertBackTickNameToNameWithReducerInputFormat

 public static String ConvertBackTickNameToNameWithReducerInputFormat(String typename, List<int> genericParameterOffsets)
 {
     int indexOfBackTick = typename.LastIndexOf('`');
     if (indexOfBackTick != -1)
     {
         string typeNameSansBackTick = typename.Substring(0, indexOfBackTick);
         if ((indexOfBackTick + 1) < typename.Length)
         {
             string textAfterBackTick = typename.Substring(indexOfBackTick + 1);
             int genericParameterCount;
             if (Int32.TryParse(textAfterBackTick, out genericParameterCount) && (genericParameterCount > 0))
             {
                 // Replace the `Number with <,,,> where the count of ',' is one less than Number.
                 StringBuilder genericTypeName = new StringBuilder();
                 genericTypeName.Append(typeNameSansBackTick);
                 genericTypeName.Append('<');
                 if (genericParameterOffsets != null)
                 {
                     genericParameterOffsets.Add(genericTypeName.Length);
                 }
                 for (int i = 1; i < genericParameterCount; i++)
                 {
                     genericTypeName.Append(',');
                     if (genericParameterOffsets != null)
                     {
                         genericParameterOffsets.Add(genericTypeName.Length);
                     }
                 }
                 genericTypeName.Append('>');
                 return genericTypeName.ToString();
             }
         }
     }
     return typename;
 }
开发者ID:tijoytom,项目名称:corert,代码行数:35,代码来源:DiagnosticMappingTables.cs

示例2: while

	// Validate a qualified identifier.
	private static void ValidateQualifiedIdentifier
				(String value, bool canBeNull)
			{
				if(value == null)
				{
					if(!canBeNull)
					{
						throw new ArgumentException
							(S._("Arg_InvalidIdentifier"));
					}
				}
				else
				{
					int posn = 0;
					int index;
					String component;
					while((index = value.IndexOf('.', posn)) != -1)
					{
						component = value.Substring(posn, index - posn);
						ValidateIdentifier(component);
						posn = index + 1;
					}
					component = value.Substring(posn);
					ValidateIdentifier(component);
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:Validator.cs

示例3: HexToColor

 public static Microsoft.Xna.Framework.Color HexToColor(String hexString)
 {
     Microsoft.Xna.Framework.Color actColor = Microsoft.Xna.Framework.Color.White;
     if (hexString.StartsWith("#") && hexString.Length == 7)
         actColor = new Microsoft.Xna.Framework.Color(
             int.Parse(hexString.Substring(1,2), System.Globalization.NumberStyles.HexNumber),
             int.Parse(hexString.Substring(3,2), System.Globalization.NumberStyles.HexNumber),
             int.Parse(hexString.Substring(5,2), System.Globalization.NumberStyles.HexNumber)
             );
     return actColor;
 }
开发者ID:poksme,项目名称:TetriClimber,代码行数:11,代码来源:Constants.cs

示例4: Stylesheet

 public Stylesheet(String stylesheet)
 {
     char currentChar = '\0';
     StringBuilder buffer = new StringBuilder();
     for (int i = 0, j = 0; i < stylesheet.Length; i++, j++)
     {
         currentChar = stylesheet[i];
         switch (currentChar)
         {
             case ' ':
                 continue;
             case '{':
                 {
                     int endIndex = stylesheet.IndexOf('}', i);
                     String block = stylesheet.Substring(i, endIndex - i);
                     Selector selector = new Selector(buffer.ToString().Trim(), block);
                     this.selectors.Add(selector);
                     i = endIndex - 1;
                     buffer.Clear();
                     continue;
                 }
             default:
                 buffer.Append(currentChar);
                 break;
         }
     }
 }
开发者ID:krikelin,项目名称:SpiderView,代码行数:27,代码来源:CSS.cs

示例5: GetDirectory

        internal static String GetDirectory(String path)
        {
            if (path == null || path.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.UrlPath_EmptyPathHasNoDirectory));
            }

            if (path[0] != '/' && path[0] != appRelativeCharacter)
            {
                throw new ArgumentException(SR.GetString(SR.UrlPath_PathMustBeRooted));
            }

            // Make sure there is a filename after the last '/'
            Debug.Assert(path[path.Length-1] != '/', "Path should not end with a /");

            string dir = path.Substring(0, path.LastIndexOf('/'));

            // If it's the root dir, we would end up with "".  Return "/" instead
            if (dir.Length == 0)
            {
                return "/";
            }

            return dir;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:25,代码来源:UrlPath.cs

示例6: BindingMemberInfo

	// Constructor.
	public BindingMemberInfo(String dataMember)
			{
				if(dataMember == null)
				{
					dataMember = String.Empty;
				}
				int index = dataMember.LastIndexOf('.');
				if(index != -1)
				{
					field = dataMember.Substring(index + 1);
					path = dataMember.Substring(0, index);
				}
				else
				{
					field = dataMember;
					path = String.Empty;
				}
				fieldType = null;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:20,代码来源:BindingMemberInfo.cs

示例7: WritePascalString

		public void WritePascalString(String s)
		{
			Char[] c = s.Length > 255 ? s.Substring(0, 255).ToCharArray() : s.ToCharArray();

			base.Write((Byte)c.Length);
			base.Write(c);

			Int32 realLength = c.Length + 1;

			if ((realLength % 2) == 0) return;

			for (Int32 i = 0; i < (2 - (realLength % 2)); i++) base.Write((Byte)0);

			if (AutoFlush) Flush();
		}
开发者ID:svarogg,项目名称:System.Drawing.PSD,代码行数:15,代码来源:BinaryReverseWriter.cs

示例8: SoapFault

	internal SoapFault(SerializationInfo info, StreamingContext context)
			{
				faultCode = info.GetStringIgnoreCase("faultcode");
				if(faultCode != null)
				{
					int posn = faultCode.IndexOf(':');
					if(posn != -1)
					{
						faultCode = faultCode.Substring(posn + 1);
					}
				}
				faultString = info.GetStringIgnoreCase("faultstring");
				faultActor = info.GetStringIgnoreCase("faultactor");
				serverFault = info.GetValueIgnoreCase("detail", typeof(Object));
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:15,代码来源:SoapFault.cs

示例9: Parse

	// Parse a value into an instance of this class.
	public static DateTime Parse(String value)
			{
				if(value == null)
				{
					return DateTime.MinValue;
				}
				else if(value.EndsWith("Z"))
				{
					value = value.Substring(0, value.Length - 1) + "-00:00";
				}
				try
				{
					return DateTime.ParseExact
						(value, formats, CultureInfo.InvariantCulture,
					 	 DateTimeStyles.None);
				}
				catch(Exception)
				{
					throw new RemotingException(_("Arg_InvalidSoapValue"));
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:22,代码来源:SoapDateTime.cs

示例10: OnCacheItemRemoved

        /*
         * Handle callbacks from the cache for session state expiry
         */
        public void OnCacheItemRemoved(String key, Object value, CacheItemRemovedReason reason) {
            InProcSessionState state;
            String id;

            Debug.Trace("SessionOnEnd", "OnCacheItemRemoved called, reason = " + reason);

            PerfCounters.DecrementCounter(AppPerfCounter.SESSIONS_ACTIVE);

            state = (InProcSessionState) value;
            
            if ((state._flags & (int)SessionStateItemFlags.IgnoreCacheItemRemoved) != 0 ||
                (state._flags & (int)SessionStateItemFlags.Uninitialized) != 0) {
                Debug.Trace("SessionOnEnd", "OnCacheItemRemoved ignored");
                return;
            }
            
            switch (reason) {
                case CacheItemRemovedReason.Expired: 
                    PerfCounters.IncrementCounter(AppPerfCounter.SESSIONS_TIMED_OUT);
                    break;

                case CacheItemRemovedReason.Removed:
                    PerfCounters.IncrementCounter(AppPerfCounter.SESSIONS_ABANDONED);
                    break;

                default:
                    break;    
            }

            TraceSessionStats();

            if (_expireCallback != null) {
                id = key.Substring(CACHEKEYPREFIXLENGTH);

                _expireCallback(id, SessionStateUtility.CreateLegitStoreData(null,
                                                        state._sessionItems,
                                                        state._staticObjects,
                                                        state._timeout));
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:43,代码来源:InProcStateClientManager.cs

示例11: AccessingLoginPage

        internal static bool AccessingLoginPage(HttpContext context, String loginUrl) {
            if (String.IsNullOrEmpty(loginUrl)) {
                return false;
            }

            loginUrl = GetCompleteLoginUrl(context, loginUrl);
            if (String.IsNullOrEmpty(loginUrl)) {
                return false;
            }

            // Ignore query string
            int iqs = loginUrl.IndexOf('?');
            if (iqs >= 0) {
                loginUrl = loginUrl.Substring(0, iqs);
            }

            String requestPath = context.Request.Path;

            if (StringUtil.EqualsIgnoreCase(requestPath, loginUrl)) {
                return true;
            }

            // It could be that loginUrl in config was UrlEncoded (ASURT 98932)
            if (loginUrl.IndexOf('%') >= 0) {
                String decodedLoginUrl;
                // encoding is unknown try UTF-8 first, then request encoding

                decodedLoginUrl = HttpUtility.UrlDecode(loginUrl);
                if (StringUtil.EqualsIgnoreCase(requestPath, decodedLoginUrl)) {
                    return true;
                }

                decodedLoginUrl = HttpUtility.UrlDecode(loginUrl, context.Request.ContentEncoding);
                if (StringUtil.EqualsIgnoreCase(requestPath, decodedLoginUrl)) {
                    return true;
                }
            }

            return false;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:40,代码来源:AuthenticationConfig.cs

示例12: Resolve

        public static MagnetLink Resolve(String magnetLink)
        {
            IEnumerable<KeyValuePair<String, String>> values = null;

            if (IsMagnetLink(magnetLink))
            {
                values = SplitURLIntoParts(magnetLink.Substring(8));
            }

            if (values == null) return null;

            MagnetLink magnet = new MagnetLink();

            foreach (KeyValuePair<string, string> pair in values)
            {
                if (pair.Key == "xt")
                {
                    if (!IsXTValidHash(pair.Value))
                    {
                        continue;
                    }

                    magnet.HashString = pair.Value.Substring(9);
                }

                if (pair.Key == "dn")
                {
                    magnet.Name = pair.Value;
                }

                if (pair.Key == "tr")
                {
                    magnet.Trackers.Add(pair.Value);
                }
            }

            return magnet;
        }
开发者ID:alex-kir,项目名称:System.Net.Torrent,代码行数:38,代码来源:MagnetLink.cs

示例13: LocateNextSelectedDate

 private int LocateNextSelectedDate(String webCalendarHtml, int startingIndex)
 {
     int tagBeginIndex = startingIndex;
     do
     {
         tagBeginIndex = webCalendarHtml.IndexOf(_selectedDateSearchCellTag, tagBeginIndex, StringComparison.Ordinal);
         if (tagBeginIndex >= 0)
         {
             int tagEndIndex = webCalendarHtml.IndexOf(">", tagBeginIndex + _bgColorInsertionPointInPattern, StringComparison.Ordinal);
             Debug.Assert(tagEndIndex >= 0);
             String tagComplete = webCalendarHtml.Substring(tagBeginIndex, tagEndIndex-tagBeginIndex+1);
             if (tagComplete.IndexOf(_selectedDateSearchAttr, StringComparison.Ordinal) >= 0)
             {
                 return tagBeginIndex;
             }
             else
             {
                 tagBeginIndex += _bgColorInsertionPointInPattern;
             }
         }
     }
     while (tagBeginIndex >= 0);
     return -1;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:24,代码来源:HtmlCalendarAdapter.cs

示例14: Reduce

        internal static String Reduce(String path)
        {
            // ignore query string
            String queryString = null;
            if (path != null)
            {
                int iqs = path.IndexOf('?');
                if (iqs >= 0)
                {
                    queryString = path.Substring(iqs);
                    path = path.Substring(0, iqs);
                }
            }

            int length = path.Length;
            int examine;

            // Make sure we don't have any back slashes
            path = path.Replace('\\', '/');

            // quickly rule out situations in which there are no . or ..

            for (examine = 0; ; examine++)
            {
                examine = path.IndexOf('.', examine);
                if (examine < 0)
                {
                    return (queryString != null) ? (path + queryString) : path;
                }

                if ((examine == 0 || path[examine - 1] == '/')
                    && (examine + 1 == length || path[examine + 1] == '/' ||
                        (path[examine + 1] == '.' && (examine + 2 == length || path[examine + 2] == '/'))))
                {
                    break;
                }
            }

            // OK, we found a . or .. so process it:

            ArrayList list = new ArrayList();
            StringBuilder sb = new StringBuilder();
            int start;
            examine = 0;

            for (;;)
            {
                start = examine;
                examine = path.IndexOf('/', start + 1);

                if (examine < 0)
                {
                    examine = length;
                }

                if (examine - start <= 3 &&
                    (examine < 1 || path[examine - 1] == '.') &&
                    (start + 1 >= length || path[start + 1] == '.'))
                {
                    if (examine - start == 3)
                    {
                        if (list.Count == 0)
                        {
                            throw new Exception(SR.GetString(SR.UrlPath_CannotExitUpTopDirectory));
                        }

                        sb.Length = (int)list[list.Count - 1];
                        list.RemoveRange(list.Count - 1, 1);
                    }
                }
                else
                {
                    list.Add(sb.Length);

                    sb.Append(path, start, examine - start);
                }

                if (examine == length)
                {
                    break;
                }
            }

            return sb.ToString() + queryString;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:85,代码来源:UrlPath.cs

示例15: PathToContentPath

 public virtual String PathToContentPath( String path )
 {
     if( path.StartsWith("monkey://data/") ) return "Content/monkey/"+path.Substring( 14 );
     return "";
 }
开发者ID:Beaker13,项目名称:monkeyxamarin,代码行数:5,代码来源:xamarinapp.cs


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