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


C# String.IndexOf方法代码示例

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


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

示例1: getFirstLineOfString

        /// <summary>
        /// 获取指定字符串的第一行内容,其方法是查找\r或\n的位置
        /// 如果只有一个,则直接依据其索引从0开始截取子串即可
        /// 如果找到两个,则取最小的那个作为索此截取子串
        /// 如果没有找到,返回整个字串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static String getFirstLineOfString(String str)
        {
            if (String.IsNullOrEmpty(str))
            {
                return null;
            }

            int indexOfR = str.IndexOf("\r");
            int indexOfN = str.IndexOf("\n");
            if (indexOfN == -1 && indexOfR == -1)
            {
                return str;
            }

            if (indexOfN != -1 && indexOfR != -1)
            {
                int length = (indexOfN < indexOfR ? indexOfR : indexOfN) - 1;
                return str.Substring(0, length);

            }

            if (indexOfN != -1 && indexOfR == -1)
            {
                return str.Substring(0, indexOfN - 1);

            }

            if (indexOfN == -1 && indexOfR != -1)
            {
                return str.Substring(0, indexOfR - 1);

            }
            return null;
        }
开发者ID:puma007,项目名称:PersonalInfoForWPF,代码行数:42,代码来源:StringUtils.cs

示例2: AddMessage

		protected override void AddMessage(String message)
		{
			if( message.IndexOf("AFC") == -1 && message.IndexOf("NFC") == -1 )
			{
				base.AddMessage (message);
			}
		}
开发者ID:tecmopsycho,项目名称:tsbtools,代码行数:7,代码来源:CXRomScheduleHelper.cs

示例3: GetDeclaredEncoding

 /**
  *
  * @param decl a string from header or meta tag to detect encoding
  * @return encoding String
  */
 public static String GetDeclaredEncoding(String decl)
 {
     if (decl == null)
         return null;
     int idx = decl.IndexOf("encoding");
     if (idx < 0)
         return null;
     int idx1 = decl.IndexOf('"', idx);
     int idx2 = decl.IndexOf('\'', idx);
     if (idx1 == idx2)
         return null;
     if (idx1 < 0 && idx2 > 0 || idx2 > 0 && idx2 < idx1) {
         int idx3 = decl.IndexOf('\'', idx2 + 1);
         if (idx3 < 0)
             return null;
         return decl.Substring(idx2 + 1, idx3 - (idx2 + 1));
     }
     if (idx2 < 0 && idx1 > 0 || idx1 > 0 && idx1 < idx2) {
         int idx3 = decl.IndexOf('"', idx1 + 1);
         if (idx3 < 0)
             return null;
         return decl.Substring(idx1 + 1, idx3 - (idx1 + 1));
     }
     return null;
 }
开发者ID:boecko,项目名称:iTextSharp,代码行数:30,代码来源:EncodingUtil.cs

示例4: ContentType

 public ContentType(String mime)
 {
     // this allows us to correctly process ctypes like "text/html; charset=utf-8"
     // todo. investigate the MIME spec and implement this thouroughly
     var sliceAt = mime.IndexOf(";") == -1 ? mime.Length : mime.IndexOf(";");
     Mime = mime.Substring(0, sliceAt); ;
 }
开发者ID:xeno-by,项目名称:xenogears,代码行数:7,代码来源:ContentType.cs

示例5: parse

 private void parse(String message)
 {
     int i = -1;
     int j = message.IndexOf(" :");
     String trailing = "";
     if (message.StartsWith(":"))
     {
         i = message.IndexOf(" ");
         prefix = message.Substring(1, i - 1);
     }
     if (j >= 0)
     {
         trailing = message.Substring(j + 2);
     }
     else
     {
         j = message.Length;
     }
     var commandAndParameters = message.Substring(i + 1, j - i - 1).Split(' ');
     command = commandAndParameters.First();
     if (commandAndParameters.Length > 1)
         parameters = commandAndParameters.Skip(1).ToArray();
     if (!String.IsNullOrEmpty(trailing))
     {
         parameters = parameters.Concat(new string[] { trailing }).ToArray();
     }
 }
开发者ID:WNSoft,项目名称:XYRCConsole,代码行数:27,代码来源:Message.cs

示例6: DoLogin

        public override bool DoLogin()
        {
            Logout(true);
            String homePage = "http://www.myspace.com";
            String loginUrl = "http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken=";
            try
            {
                htmlResponse = httpUtils.GetHttpResponse(homePage, false);
                reffer = homePage;
                String tempStr = "MyToken=";
                int pos = htmlResponse.IndexOf(tempStr);
                myToken = htmlResponse.Substring(pos + tempStr.Length);
                myToken = myToken.Substring(0, myToken.IndexOf("\""));
                loginUrl += myToken;
                postString = "email=" + UserId + "&password=" + HttpUtility.UrlEncode(Password) + "&Submit22_x=33&Submit22_y=10";
                htmlResponse = httpUtils.GetHttpResponse(loginUrl, false, postString, reffer);
                if (htmlResponse.IndexOf("<input type=\"text\" name=\"email\"") == -1)
                {
                    // Begin Outer If
                    if (htmlResponse.IndexOf("Member Login") == -1)
                    {
                        // Begin 1st inner if
                        if (htmlResponse.IndexOf("Skip this Advertisement") > 1)
                        {
                            htmlResponse = htmlResponse.Substring(0, htmlResponse.IndexOf("Skip this Advertisement"));
                            tempStr = "<a href=\"";
                            String urlToFetch = htmlResponse.Substring(htmlResponse.IndexOf(tempStr) + tempStr.Length);
                            urlToFetch = urlToFetch.Substring(0, urlToFetch.IndexOf("\""));
                            htmlResponse = httpUtils.GetHttpResponse(urlToFetch, false, "", loginUrl);

                        }
                        //End 1st inner if.

                        // Begin of 2nd inner if
                        if (htmlResponse.IndexOf("You have\n <span><a href=\"") == -1)
                        {
                            htmlResponse = httpUtils.GetHttpResponse("http://home.myspace.com/index.cfm?fuseaction=user", false);

                        }
                        // End of 2nd inner if
                        tempStr = "<span><a href=\"";
                        String fPage = htmlResponse.Substring(htmlResponse.IndexOf(tempStr) + tempStr.Length);
                        fPage = fPage.Substring(0, fPage.IndexOf("\""));

                        IsLoggedIn = true;
                    }
                }
                else
                {
                    IsLoggedIn = false;
                }
            }
            //Outer if close
            // End of outer if
            catch (Exception)
            {
                IsLoggedIn = false;
            }
            return IsLoggedIn;
        }
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:60,代码来源:MyspaceImporter.cs

示例7: W3CDateTimeToDateTime

        public static DateTime W3CDateTimeToDateTime(String w3cDateTime)
        {
            DateTime dt;

            if (w3cDateTime.IndexOf('T') != -1) {
                if (w3cDateTime.IndexOf('Z') != -1) {
                    dt = DateTime.ParseExact(w3cDateTime,
                                             W3CDateTimePatternsUTC,
                                             DateTimeFormatInfo.InvariantInfo,
                                             DateTimeStyles.NoCurrentDateDefault);
                    dt = dt.ToLocalTime();
                } else {
                    dt = DateTime.ParseExact(w3cDateTime,
                                             W3CDateTimePatternsTZ,
                                             DateTimeFormatInfo.InvariantInfo,
                                             DateTimeStyles.NoCurrentDateDefault);
                }
            } else {
                dt = DateTime.ParseExact(w3cDateTime,
                                         W3CDateTimePatternsBasic,
                                         DateTimeFormatInfo.InvariantInfo,
                                         DateTimeStyles.NoCurrentDateDefault);
                dt = dt.ToLocalTime();
            }
            return dt;
        }
开发者ID:BackupTheBerlios,项目名称:xbel-sharp-svn,代码行数:26,代码来源:W3CDateTimeUtils.cs

示例8: Wall

        public Wall(String Name, String ModelName, Model SentModel, Vector3 ModelPosition, Vector3 ModelRotation, GraphicsDevice device, Boolean moveable, Boolean pickup, float bounciness, Boolean levitating, String ActionInfo)
            : base(Name, ModelName, SentModel, ModelPosition, ModelRotation, device, moveable, pickup, bounciness, levitating)
        {
            String Dimensions = ActionInfo.Substring(ActionInfo.IndexOf("Wall{") + 5, ActionInfo.IndexOf("}") - ActionInfo.IndexOf("Wall{") - 5);
            this.Length = float.Parse(Dimensions.Substring(Dimensions.IndexOf("Length:") + 7, Dimensions.IndexOf(';', Dimensions.IndexOf("Length:")) - Dimensions.IndexOf("Length:") - 7));
            this.Width = float.Parse(Dimensions.Substring(Dimensions.IndexOf("Width:") + 6, Dimensions.IndexOf(';', Dimensions.IndexOf("Width:")) - Dimensions.IndexOf("Width:") - 6));
            this.Height = float.Parse(Dimensions.Substring(Dimensions.IndexOf("Height:") + 7, Dimensions.IndexOf(';', Dimensions.IndexOf("Height:")) - Dimensions.IndexOf("Height:") - 7));
            int storeSpot = 0;
            try
            {
                wallColor = new Color(
                int.Parse(Dimensions.Substring(storeSpot = (Dimensions.IndexOf("R:", Dimensions.IndexOf("Color(")) + 2), Dimensions.IndexOf(",", Dimensions.IndexOf("R:", Dimensions.IndexOf("Color("))) - storeSpot)),
                int.Parse(Dimensions.Substring(storeSpot = (Dimensions.IndexOf("G:", Dimensions.IndexOf("Color(")) + 2), Dimensions.IndexOf(",", Dimensions.IndexOf("G:", Dimensions.IndexOf("Color("))) - storeSpot)),
                int.Parse(Dimensions.Substring(storeSpot = (Dimensions.IndexOf("B:", Dimensions.IndexOf("Color(")) + 2), Dimensions.IndexOf(",", Dimensions.IndexOf("B:", Dimensions.IndexOf("Color("))) - storeSpot)),
                int.Parse(Dimensions.Substring(storeSpot = (Dimensions.IndexOf("A:", Dimensions.IndexOf("Color(")) + 2), Dimensions.IndexOf(")", Dimensions.IndexOf("A:", Dimensions.IndexOf("Color("))) - storeSpot)));
            }
            catch (Exception e) { }

            //VerticesMasterList.Add(new List<VertexPositionNormalColor>(0));

            this.LastPosition = this.Position;
            this.LastRotation = this.modelRotation;
            this.CalculateBoundingBox();
            this.CalculateBox();

            //Walls should not be moveable or pickupable by default - LIES!!!!
            /*
            this.Moveable = false;
            this.PickUpable = false;
            this.IsLevitating = true;
             */
        }
开发者ID:schuylermartin45,项目名称:LHS-The-Video-Game,代码行数:32,代码来源:Wall.cs

示例9: Pascal

        public Pascal(String operation, String filePath, String flags)
        {
            try{
                bool intermediate = flags.IndexOf('i') > 1;
                bool xref = flags.IndexOf('x') > 1;
                source = new Source(new StreamReader(filePath));
                source.AddMessageListener(new SourceMessageListener());

                parser = FrontEndFactory.CreateParser("pascal","top-down",source);
                parser.AddMessageListener(new ParserMessageListener());

                backend = BackendFactory.CreateBackend("compile");
                backend.AddMessageListener(new BackendMessageListener());

                parser.Parse();
                source.close();

                intermediateCode = parser.IntermediateCode;
                symbolTable = Parser.SymbolTable;

                backend.Process(intermediateCode,symbolTable);
            }
            catch(Exception ex){
                Console.WriteLine ("Internal translation error");
                Console.WriteLine (ex.StackTrace);
            }
        }
开发者ID:hardvain,项目名称:pascal-compiler,代码行数:27,代码来源:Pascal.cs

示例10: GetCitiesFromPageHtml

        IEnumerable<City> GetCitiesFromPageHtml(String html)
        {
            var startRegionMarker = "<select id=\"filterAddressTown\"";
            var endRegionMarker = "</select>";

            var startIndex = html.IndexOf(startRegionMarker);
            var endIndex = html.IndexOf(endRegionMarker, startIndex) + endRegionMarker.Length;

            var citiesXml = html.Substring(startIndex, endIndex - startIndex);

            var cities = new List<City>();

            var parsed = XDocument.Parse(citiesXml);
            foreach (var elem in parsed.Elements().First().Elements())
            { 
                var city = new City()
                {
                    Id = elem.Attribute("value").Value.Trim(),
                    Name = elem.Value.Trim()
                };

                if (city.Id == "0")
                    continue;

                cities.Add(city);
            }

            return cities;
        }
开发者ID:alpospb,项目名称:Mining,代码行数:29,代码来源:SparExpressMiner.cs

示例11: GetShops

        IEnumerable<Shop> GetShops(String html, IEnumerable<City> cities)
        {
            var start = "var myLoadYMapsItemsVar=";
            var end = "};";
            var startIndex = html.IndexOf(start) + start.Length;
            var endIndex = html.IndexOf(end, startIndex) + 1;

            var shopsJsonText = html.Substring(startIndex, endIndex - startIndex);
            var shopsJson = JsonConvert.DeserializeObject<ShopsJson>(shopsJsonText);

            var shops = new List<Shop>();
            var citiesDict = cities.ToDictionary(c => c.Id);
            foreach (var shopJson in shopsJson.items)
            {
                String shirota, dolgota;
                ParseHelper.GetCoordinates(shopJson.gps, out shirota, out dolgota);
                
                var shop = new Shop() 
                {
                    Address = shopJson.name,
                    Dolgota = dolgota,
                    Shirota = shirota,
                    City = citiesDict[shopJson.per_id].Name,
                    TimeWork = shopJson.time
                };

                shops.Add(shop);
            }

            return shops;
        }
开发者ID:alpospb,项目名称:Mining,代码行数:31,代码来源:SparExpressMiner.cs

示例12: modifyRecursively

 /// <summary>
 /// 
 /// </summary>
 /// <param name="ob"></param>
 /// <param name="fieldPath"></param>
 /// <param name="fieldValue"></param>
 public static void modifyRecursively(Object ob, String fieldPath, String fieldValue)
 {
     if (ob == null)
     {
         return;
     }
     if (!fieldPath.Contains("."))
     {
         modifyValueOfFieldAccordingToTable(ob, fieldPath, fieldValue);
     }
     else
     {
         String prefix = fieldPath.Substring(0, fieldPath.IndexOf('.'));
         Object o;
         o = ob.GetType().GetProperty(prefix, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
         if (o != null)
         {
             PropertyInfo myProp = (PropertyInfo)o;
             Object subObject = myProp.GetValue(ob, null);
             String toPass = fieldPath.Substring(fieldPath.IndexOf('.') + 1);
             modifyRecursively(subObject, toPass, fieldValue);
         }
         else
         {
             o = ob.GetType().GetField(prefix, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
             FieldInfo myField = (FieldInfo)o;
             Object subObject = myField.GetValue(ob);
             String toPass = fieldPath.Substring(fieldPath.IndexOf('.') + 1);
             modifyRecursively(subObject, toPass, fieldValue);
         }
     }
 }
开发者ID:tonyx,项目名称:LabelsLocalization,代码行数:38,代码来源:LabelUtils.cs

示例13: NetworkShare

 /// <summary>
 /// Constructor with UNC
 /// </summary>
 /// <param name="path">The share name - UNC</param>
 public NetworkShare( String path )
 {
     String hostName = "";
     // check if the UNC is valid
     unc = (String) path.Clone();
     if( path.StartsWith( @"\\" ) )
     {
         path = path.Remove( 0, 2 );
         int i = path.IndexOf( @"\" );
         if( i < 0 )
         {
             goto _abort;
         }
         hostName = path.Substring( 0, path.IndexOf( @"\" ) );
         path = path.Remove( 0, i );
         if( path == null || path.Length < 1 )
         {
             goto _abort;
         }
         // remove the first "\"
         remotePath = (String) path.Remove( 0, 1 );
         if( remotePath == null || remotePath.Length < 1 )
         {
             goto _abort;
         }
         goto _ok;
     }
     _abort:
     throw new Exception( "Invalid UNC path: " + unc );
     _ok:
     {
         host = new NetworkHost( hostName, 0 /* dummy */ );
     }
 }
开发者ID:BackupTheBerlios,项目名称:shareindex,代码行数:38,代码来源:NetworkShare.cs

示例14: imgtext

 private String imgtext(String imgs)
 {
     String img = "";
     int ps = imgs.IndexOf("<IMG");
     if (ps >= 0)
     {
         imgs = imgs.Substring(ps);
         ps = imgs.IndexOf(">");
         if (ps >= 0)
         {
             img = imgs.Substring(0, ps + 1);
             ps = img.IndexOf("src=");
             img = img.Substring(ps + 5);
             ps = img.IndexOf(" ");
             if (ps >= 0)
             {
                 img = img.Substring(0, ps - 1);
             }
         }
     }
     if (img.Length > 0)
         if (!img.ToLower().StartsWith("http://"))
         {
             JpSite site = new JpSite();
             img = "http://" + site.host + img;
         }
     return img;
 }
开发者ID:wjszxli,项目名称:xdjb,代码行数:28,代码来源:JpRSSItem.cs

示例15: WhoLine

        public WhoLine(IrcLine baseLine)
            : base(baseLine)
        {
            if(baseLine.Numeric != 352)
                throw new ArgumentOutOfRangeException("baseLine", "RPL_WHOREPLY 352 expected");
            if(Parameters.Length < 8)
                throw new ArgumentOutOfRangeException("baseLine", "Need a minimum of 8 parameters");

            UserValue = new UserInfo(Parameters[5], Parameters[2], Parameters[3], Client);
            List<Mode> modes = new List<Mode>();
            int i = 1;

            IsAwayValue = Parameters[6][0] == 'G';
            IsOperValue = Parameters[6][i] == '*';

            if(IsOper)
                i++;

            for(; i < Parameters[6].Length; i++)
            {
                if(Client.Standard.UserPrefixFlags.ContainsKey(Parameters[6][i]))
                {
                    modes.Add(new Mode(Client.Standard.UserPrefixFlags[Parameters[6][i]], FlagArt.Set, User.NickName));
                }
            }

            ModesValue = modes.ToArray();

            RealNameValue = Parameters[7];

            if(!int.TryParse(RealNameValue.Substring(1, RealNameValue.IndexOf(" ")), out HopCountValue))
                throw new ArgumentOutOfRangeException("baseLine", "Invalid hop count, integer expected");

            RealNameValue = RealNameValue.Substring(RealNameValue.IndexOf(" ") + 1);
        }
开发者ID:hapm,项目名称:IrcShark,代码行数:35,代码来源:WhoLine.cs


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