Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text?
Selecting a Range of text? Selecting a Range of text?
Selecting a Range of text?
Go Back  Xtreme Visual Basic Talk > > > Selecting a Range of text?


Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2010, 03:12 PM
Themanhunt Themanhunt is offline
Newcomer
 
Join Date: Oct 2010
Posts: 1
Default Selecting a Range of text?


Hello,

I'm in need of a quick guide or a code snippet to do the following.

I can split the text file easily, but this is the snag.

The text I need is within two [ ] and I want to find the text between them.

Any help?

Thanks,
Themanhunt
Reply With Quote
  #2  
Old 10-17-2010, 01:40 PM
Qua's Avatar
QuaSelecting a Range of text? Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Use a regular expression to extract the text, or make use of the string manipulation functions. The function IndexOf will give you the locations of the respective brackets and Substring will allow you to extract them once you know their locations.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 10-19-2010, 11:40 AM
santoshkumar220 santoshkumar220 is offline
Newcomer
 
Join Date: Oct 2010
Posts: 1
Cool

Try this....


string strTemp = "";
strTemp= System.IO.File.ReadAllText(Server.MapPath("YourFile.txt"));
strTemp= strTemp.Replace("[your variable]", "Hello");

System.IO.File.CreateText(filepath)

Hope this helped...
Reply With Quote
  #4  
Old 10-19-2010, 12:05 PM
Qua's Avatar
QuaSelecting a Range of text? Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Quote:
Originally Posted by santoshkumar220 View Post
Try this....


string strTemp = "";
strTemp= System.IO.File.ReadAllText(Server.MapPath("YourFile.txt"));
strTemp= strTemp.Replace("[your variable]", "Hello");

System.IO.File.CreateText(filepath)

Hope this helped...
There are several reasons why this won't work. First of all, there are no indications that this is ASP.NET application, and thus the Server variable won't be available. Second, you're replacing the text instead of extracting it. Furthermore you don't know the text you're looking for (in your example denoted 'your variable').

Use the approach I suggested in my first post.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text? Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text? Selecting a Range of text?
Selecting a Range of text?
Selecting a Range of text?
 
Selecting a Range of text?
Selecting a Range of text?
 
-->