Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I was just writing a small program to start with Visual Studio (visual basic) , and i am stuck at 1 particular position. Suppose there is 1 text box (in which user enters some sentence) and a label beside it. now i want that if User enters this sentence: "#Green# What is color of the leaf"
Then the label should contain answer Green , All i could do was to print #Green# , the whole sentence or nothing :| , What should i do so that only word/s contained inside #...# appears!! Please help ASAP :(
Posted
Updated 2-Aug-13 0:57am
v2

Hi there,

I believe the solution to your problem can be found here:
How to extract the strings between two characters[^]

It uses a regular expression to find the string and extract it.
 
Share this answer
 
Comments
AbhinavGauniyal 2-Aug-13 7:09am    
Actually i am a newbee to this, and i dont know what does 'REGEX' means , But i noticed that there was a extension posted on this. How to use that? I mean should i just copy paste that into my code and call it later to find the string or something else. Thanks for your reply Smile | :)
Pheonyx 2-Aug-13 7:11am    
That link provides sample code, the term REGEX is an abbreviation of Regular Expression and if you Google the term there are plenty of resources to explain what it is. There is a RegEx class in .Net which stores a regular expression definition which can be used repeatedly or you can take the approach that ProgramFox has detailed in solution 2 where you create it on the fly when you need it.
Hi,

Try this:
VB
label1.Text = System.Text.RegularExpressions.Regex.Match(textBox1.Text, "(?<=#)(.+)(?=#)").Value
' change label1 and textBox1 into the names of your label and text box

Hope this helps.
 
Share this answer
 
Comments
AbhinavGauniyal 2-Aug-13 7:10am    
Ok i should try this one, It looks easy to me. Thanks!
Thomas Daniels 2-Aug-13 7:11am    
You're welcome!
AbhinavGauniyal 5-Aug-13 9:43am    
Worked like a charm! Thanks Sir!
Jean A Brandelero 2-Aug-13 7:11am    
Yes, regex is the best possible solution for your problem.

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