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


C# System.IndexOf方法代码示例

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


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

示例1: checkCode

		} //end method
		
		/// <summary> Checks a code for an exact match, and using certain sequences where some 
		/// characters are wildcards (e.g. HL7nnnn).  If the pattern contains one of 
		/// " or ", " OR ", or "," each operand is checked.
		/// </summary>
		private bool checkCode(System.String code, System.String pattern)
		{
			bool match = false;
			//mod by Neal acharya - Do full match on with the pattern.  If code matches pattern then return true
			//else parse pattern to look for wildcard characters
			if (code.Equals(pattern))
			{
				match = true;
			}
			//end if 
			else
			{
				if (pattern.IndexOf(' ') >= 0 || pattern.IndexOf(',') >= 0)
				{
					SupportClass.Tokenizer tok = new SupportClass.Tokenizer(pattern, ", ", false);
					while (tok.HasMoreTokens() && !match)
					{
						System.String t = tok.NextToken();
						if (!t.ToUpper().Equals("or".ToUpper()))
							match = checkCode(code, t);
					} //end while
				}
				//end if
				else
				{
					if (code.Equals(pattern))
					{
						match = true;
					}
				} //end else
			} //end else 
			return match;
		} //end method
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:39,代码来源:AbstractCodeStore.cs

示例2: 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(System.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[i];
						if ((c < 'a' || c > 'z') && (c < 'A' || c > '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[i];
						if (c < '0' || c > '9')
						{
							return false;
						}
					}
				}
			}
			return true;
		}
开发者ID:jaychouzhou,项目名称:Ydifisofidosfj,代码行数:55,代码来源:URIResultParser.cs

示例3: IndexOfTestCase2

        public void IndexOfTestCase2()
        {
            Array array = new[]
            {
                "0",
                "1",
                "2"
            };

            var actual = array.IndexOf( "1", 0, 2 );
            Assert.AreEqual( 1, actual );

            actual = array.IndexOf( "2", 0, 2 );
            Assert.AreEqual( -1, actual );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:15,代码来源:Array.IndexOf.Test.cs

示例4: GetTargetIndex

        public override int GetTargetIndex(System.Collections.Generic.List<WorldObject> availableTargets)
        {
            var target = availableTargets
                .FirstOrDefault(x => x.Owner != 0);

            return availableTargets.IndexOf(target);
        }
开发者ID:evlogihr,项目名称:TelerikAcademy-Exercises,代码行数:7,代码来源:Giant.cs

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

示例6: GetTargetIndex

        public override int GetTargetIndex(System.Collections.Generic.List<WorldObject> availableTargets)
        {
            var target = availableTargets
                .Where(x => x.Owner != 0 && x.Owner != this.Owner)
                .OrderByDescending(x => x.HitPoints)
                .FirstOrDefault();

            return availableTargets.IndexOf(target);
        }
开发者ID:evlogihr,项目名称:TelerikAcademy-Exercises,代码行数:9,代码来源:Ninja.cs

示例7: GenericIndexOfTestCase1

 public void GenericIndexOfTestCase1()
 {
     var array = new[]
     {
         "test",
         "test2"
     };
     var actual = array.IndexOf( "test2", 1 );
     Assert.AreEqual( 1, actual );
 }
开发者ID:MannusEtten,项目名称:Extend,代码行数:10,代码来源:Array.Generic.IndexOf.Test.cs

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

示例9: resolveEntity

 /// <summary> Resolves SYSTEM and PUBLIC identifiers for CML DTDs.
 /// 
 /// </summary>
 /// <param name="publicId">the PUBLIC identifier of the DTD (unused)
 /// </param>
 /// <param name="systemId">the SYSTEM identifier of the DTD
 /// </param>
 /// <returns> the CML DTD as an InputSource or null if id's unresolvable
 /// </returns>
 public virtual XmlSourceSupport resolveEntity(System.String publicId, System.String systemId)
 {
     //logger.debug("CMLResolver: resolving ", publicId, ", ", systemId);
     systemId = systemId.ToLower();
     if ((systemId.IndexOf("cml-1999-05-15.dtd") != -1) || (systemId.IndexOf("cml.dtd") != -1) || (systemId.IndexOf("cml1_0.dtd") != -1))
     {
         //logger.info("File has CML 1.0 DTD");
         return getCMLType("cml1_0.dtd");
     }
     else if ((systemId.IndexOf("cml-2001-04-06.dtd") != -1) || (systemId.IndexOf("cml1_0_1.dtd") != -1) || (systemId.IndexOf("cml_1_0_1.dtd") != -1))
     {
         //logger.info("File has CML 1.0.1 DTD");
         return getCMLType("cml1_0_1.dtd");
     }
     else
     {
         //logger.warn("Could not resolve systemID: ", systemId);
         return null;
     }
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:29,代码来源:CMLResolver.cs

示例10: GenericIndexOfTestCase2

 public void GenericIndexOfTestCase2()
 {
     var array = new[]
     {
         "test",
         "test2",
         "test3",
         "test4"
     };
     var actual = array.IndexOf( "test3", 1, 2 );
     Assert.AreEqual( 2, actual );
 }
开发者ID:MannusEtten,项目名称:Extend,代码行数:12,代码来源:Array.Generic.IndexOf.Test.cs

示例11: DataInfo

	/// <summary> Parses the value string into a recognized type. If
	/// the type specified is not supported, the data will
	/// be held and returned as a string.
	/// *
	/// </summary>
	/// <param name="key">the context key for the data
	/// </param>
	/// <param name="type">the data type
	/// </param>
	/// <param name="value">the data
	///
	/// </param>
	public DataInfo(System.String key, System.String type, System.String value_Renamed) {
	    this.key = key;

	    if (type.ToUpper().Equals(TYPE_BOOLEAN.ToUpper())) {
		this.data = System.Boolean.Parse(value_Renamed);
	    } else if (type.ToUpper().Equals(TYPE_NUMBER.ToUpper())) {
		if (value_Renamed.IndexOf((System.Char) '.') >= 0) {
		    //UPGRADE_TODO: Format of parameters of constructor 'java.lang.Double.Double' are different in the equivalent in .NET. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1092"'
		    this.data = System.Double.Parse(value_Renamed);
		} else {
		    this.data = System.Int32.Parse(value_Renamed);
		}
	    } else {
		this.data = value_Renamed;
	    }
	}
开发者ID:BackupTheBerlios,项目名称:ch3etah-svn,代码行数:28,代码来源:DataInfo.cs

示例12: ReplaceToken

      /// <summary>Replace a string within a string</summary>
      /// <param name="in_sSourceString">The String to modify
      /// </param>
      /// <param name="in_sTokenToReplace">The Token to replace
      /// </param>
      /// <param name="in_sNewToken">The new Token
      /// </param>
      /// <param name="in_nNbTimes">The number of time, the replace operation must be done. -1 means replace all
      /// </param>
      /// <returns> String The new String
      /// </returns>
      /// <exception cref="RuntimeException">where trying to replace by a new token and this new token contains the token to be replaced
      /// </exception>
      static public System.String ReplaceToken(System.String in_sSourceString, System.String in_sTokenToReplace, System.String in_sNewToken, int in_nNbTimes)
      {
         int nIndex = 0;
         bool bHasToken = true;
         System.Text.StringBuilder sResult = new System.Text.StringBuilder(in_sSourceString);
         System.String sTempString = sResult.ToString();
         int nOldTokenLength = in_sTokenToReplace.Length;
         int nTimes = 0;
         
         // To prevent from replace the token with a token containg Token to replace
         if (in_nNbTimes == - 1 && in_sNewToken.IndexOf(in_sTokenToReplace) != - 1)
          {
            throw new System.SystemException("Can not replace by this new token because it contains token to be replaced");
         }
         
         while (bHasToken)
         {
            nIndex = sTempString.IndexOf(in_sTokenToReplace, nIndex);
            bHasToken = (nIndex != - 1);
            
            if (bHasToken)
             {
               // Control number of times
               if (in_nNbTimes != - 1)
                {
                  if (nTimes < in_nNbTimes)
                   {
                     nTimes++;
                  }
                  else
                   {
                     // If we already replace the number of times asked then go out
                     break;
                  }
               }
               
               sResult.Replace(sResult.ToString(nIndex, nIndex + nOldTokenLength - nIndex), in_sNewToken, nIndex, nIndex + nOldTokenLength - nIndex);
               sTempString = sResult.ToString();
            }
            
            nIndex = 0;
         }
         
         return sResult.ToString();
		    }
开发者ID:Orvid,项目名称:SQLInterfaceCollection,代码行数:58,代码来源:OdbString.cs

示例13: MapEditorLogic

        public MapEditorLogic(Widget widget, World world, WorldRenderer worldRenderer)
        {
            var gridButton = widget.GetOrNull<ButtonWidget>("GRID_BUTTON");
            var terrainGeometryTrait = world.WorldActor.Trait<TerrainGeometryOverlay>();

            if (gridButton != null && terrainGeometryTrait != null)
            {
                gridButton.OnClick = () => terrainGeometryTrait.Enabled ^= true;
                gridButton.IsHighlighted = () => terrainGeometryTrait.Enabled;
            }

            var zoomDropdown = widget.GetOrNull<DropDownButtonWidget>("ZOOM_BUTTON");
            if (zoomDropdown != null)
            {
                var selectedZoom = Game.Settings.Graphics.PixelDouble ? 2f : 1f;
                var selectedLabel = selectedZoom.ToString();
                Func<float, ScrollItemWidget, ScrollItemWidget> setupItem = (zoom, itemTemplate) =>
                {
                    var item = ScrollItemWidget.Setup(itemTemplate,
                        () => selectedZoom == zoom,
                        () => { worldRenderer.Viewport.Zoom = selectedZoom = zoom; selectedLabel = zoom.ToString(); });

                    var label = zoom.ToString();
                    item.Get<LabelWidget>("LABEL").GetText = () => label;

                    return item;
                };

                var options = new[] { 2f, 1f, 0.5f, 0.25f };
                zoomDropdown.OnMouseDown = _ => zoomDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
                zoomDropdown.GetText = () => selectedLabel;
                zoomDropdown.GetKey = _ => Game.Settings.Keys.TogglePixelDoubleKey;
                zoomDropdown.OnKeyPress = e =>
                {
                    var key = Hotkey.FromKeyInput(e);
                    if (key != Game.Settings.Keys.TogglePixelDoubleKey)
                        return;

                    var selected = (options.IndexOf(selectedZoom) + 1) % options.Length;
                    worldRenderer.Viewport.Zoom = selectedZoom = options[selected];
                    selectedLabel = selectedZoom.ToString();
                };
            }
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:44,代码来源:MapEditorLogic.cs

示例14: TryParse

 public static Boolean TryParse(String path, out AssDocument doc)
 {
     var modes = new[] { "[script info]", "[v4+ styles]", "[events]" }.ToList();
     if (!File.Exists(path)) throw new FileNotFoundException(path);
     doc = new AssDocument();
     using (var reader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read))) {
         var currentSection = -1;
         while (!reader.EndOfStream) {
             var line = reader.ReadLine();
             if (String.IsNullOrEmpty(line)) continue;
             line = line.Trim();
             if (modes.Contains(line.ToLower())) {
                 currentSection = modes.IndexOf(line.ToLower());
                 reader.ReadLine();
             } else {
                 switch (currentSection) {
                     case 0:
                         doc.Settings.Add(line);
                         break;
                     case 1:
                         Style styleObject;
                         if (!Style.TryParse(line, out styleObject))
                             return false;
                         doc.Styles.Add(styleObject);
                         break;
                     case 2:
                         Line lineObject;
                         if (!Line.TryParse(line, out lineObject))
                             return false;
                         doc.Lines.Add(lineObject);
                         break;
                 }
             }
         }
     }
     return true;
 }
开发者ID:Rinecamo,项目名称:SParser,代码行数:37,代码来源:AssDocument.cs

示例15: Tokenize

		private ArrayList Tokenize(System.String input)
		{
			ArrayList returnVect = new ArrayList(10);
			int nextGapPos;
			for (int curPos = 0; curPos < input.Length; curPos = nextGapPos)
			{
				char ch = input[curPos];
				if (System.Char.IsWhiteSpace(ch))
					curPos++;
				nextGapPos = input.Length;
				for (int i = 0; i < "\r\n\t \x00A0".Length; i++)
				{					
					int testPos = input.IndexOf((Char) "\r\n\t \x00A0"[i], curPos);
					if (testPos < nextGapPos && testPos != - 1)
						nextGapPos = testPos;
				}
				
				System.String term = input.Substring(curPos, (nextGapPos) - (curPos));
				//if (!stopWordHandler.isWord(term))
				returnVect.Add(term);
			}
			
			return returnVect;
		}
开发者ID:kblc,项目名称:Royalty,代码行数:24,代码来源:Tokeniser.cs


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