[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
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
?
383 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
  • 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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

864 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