?
Solved

C#  Csharp findin a string within a string when you have a starting point to go from

Posted on 2011-03-19
7
Medium Priority
?
370 Views
Last Modified: 2013-12-17
have a string that i am trying to find.
as in <br> which starts 72 to 90chars in for example an i need to start the search at say char 35 or may be 45 dependng on what was last found
am using idx = str.IndexOf("  string ")  but this does not allow me to start from so many characters in
any help would be helpful
especially looking for a good web site with all the code functions published with examples
0
Comment
Question by:sydneyguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35174174
IndexOf() is overloaded to take a 2nd parameter of starting index:
string s = "Hello World!";

int index = s.IndexOf("W", 2);

Open in new window

0
 

Author Comment

by:sydneyguy
ID: 35174186
thanks most appreciated.
do you know any sites with a really good range of c# functions and examples please
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35174237
No I do not, but a quick search returned the following:


Also, you should have Intellisense, if you are using Visual Studio, which will show you when a function is overloaded.

Intellisense
Here you can see that the IndexOf() method has 9 overloads and the 4th overload takes in a string to find and a starting index to begin searching from.

You can also use the Object Browser (View->Object Browser) to view the methods for classes. For example, here is a sampling of what is shown for the string class:

 String Class Members
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:sydneyguy
ID: 35174246
i have intelli sense running but when it come to a function that i need being
i know that my start point is 157 chars in
but what i need to be able to do is to serch going to the left to the beginning and find the first match substring.
so instead of starting at loc 57 and then search in from there to the end i need to start in the middle at some given loc and search back towards the beginnings and find the first match  some sort of
str.InsexOf("data"); but going in the oppoiste dir given a starting point
any ideas then i will close out the question
thanks for the help so far
0
 

Author Comment

by:sydneyguy
ID: 35174258
got it its str.lastIndexOf("data",100);
works perfect thanks for the help
0
 

Author Closing Comment

by:sydneyguy
ID: 35174261
thanks for the help
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35174275
I think for what it sounds like you want to do, you would need a combination of two functions:

string s = "Hello World! Hello.";

int index = s.Substring(0, 7).LastIndexOf("ell");

Open in new window


Here, you would put your starting location where you see the 7. This will give you the substring from the first character to your expected starting position. You would then use LastIndexOf() to find the last occurrence of your search string within this "new" string.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question