AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How to search a string and display 10 characters before and after the string?
Posted by Sharmila on  9/8/2009 3:20:39 AM Category: C#
Add to my favorites
Email to friend
In C#,
search a string and display 10 characters before and after the string

Post Your Reply Post New Question

 Viewer's Reply
Display 10 Characters Before and After Search String
Answered By Moderator1 on 12/18/2009 10:18:06 PM
Hi,

Please try my logic below.

string str = "I have been refining the method used, and have this alternative implementation.";
int StartIndex = str.IndexOf("method");
int EndIndex = str.LastIndexOf("method");

string result = str.Substring(StartIndex - 10, EndIndex + 10);
Response.Write("Result String:" + result);
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Simply SQL - Free 111 Page Preview!
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Many .NET teams are underperforming, is yours?