[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register 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
?
377 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

650 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