Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have below string text.

One 5
====================================================
A:\Hello.txt -test
====================================================
One 1 Two 2 Three 3


with above string, I want to find "One 1"(which will be after "===" line)

Kindly suggest
Posted
Comments
[no name] 26-Sep-13 7:38am    
Okay and what have you tried?
yrishi 26-Sep-13 8:28am    
I am able to find "One" word by using "^One" Regex
The issue is, "One" is present multiple times in string as I want to find only when its comes after "==" line..
Thanks7872 26-Sep-13 8:09am    
Use reply button while making comment.
yrishi 26-Sep-13 8:18am    
Used same one..(even this time also) what happened??
Thanks7872 26-Sep-13 8:20am    
I think you intended to comment to ThePhantomUpvoter,so use reply button on his comment. You made comment to your question.

Use this regex, making sure that the Multiline option is NOT turned on:
\n=+\nOne


In the default mode, you can match newlines with \n and continue matching from one line to the next. So my regex looks for a newline followed by all "=" until another newline, then the word "One".
 
Share this answer
 
v2
Comments
yrishi 27-Sep-13 0:58am    
Thanks Brian. will check it.
If your patter doesn't change, you can use combination of String.Substring Method[^] and String.LastIndexOf Method[^] to find it.
For Ex - suppose the above string is stored in a variable str. Using above methods you could write something like
C#
str.Substring(str.LastIndexOf("==="), str.IndexOf(" ") + 1);

Please note that this is just an example. Though it will give a correct output for your question, you must fine tune it based on your requirement (for ex if you have 2 or more digit numbers).

Hope this gives you an idea.
 
Share this answer
 
Comments
yrishi 27-Sep-13 0:59am    
Thanks Ankur. will check it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900