Solved

Insert Into A String From Textbox

Posted on 2009-04-05
7
334 Views
Last Modified: 2012-05-06
Hello,

Here is my little problem.  I am tying to figure out a way so that when someone puts a certing symbol in a textbox upon pressing a button that symbol turns into a string and is inserted into the string they already entered.

Ex.
If I write "Hello (%) How are you"  I would like the (%) to be converted into "Hello GetName(Player) How are you" when it is outputted into a text file.

(%) = GetName(Player)

This is the part of my code where it reads the textbox:

sw.WriteLine(vbTab & vbTab & vbTab & "Say(QuestGiver, " & Chr(34) & txtQuestAccSay.Text & Chr(34) & Chr(41))

sw is my StreamWriter

Sorry is this is a newb question im still learning.
Thank you
0
Comment
Question by:Daniel112
[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
  • 2
7 Comments
 
LVL 4

Assisted Solution

by:CraigLazar
CraigLazar earned 200 total points
ID: 24074500
Hi,
If i understand your question, u can use the replace statement to do this fot u.
dim tmpStr as string
ex. tmpstr = replace(textbox1,"(%)","GetName(Player)")
What this function does is it takes the source string as paramter 1, then the value u want to replace as 2nd paramter, then the 3rd paramter is what u want to replace it with.
sw.WriteLine(vbTab & vbTab & vbTab & "Say(QuestGiver, " & Chr(34) & replace(txtQuestAccSay.Text,"(%)","GetName(Player)") & Chr(34) & Chr(41))
 
 hope this helps
 
 
 
0
 

Author Comment

by:Daniel112
ID: 24074969
If I do this I get an error saying expression produces no value.
But this is exactly what I am trying to do.
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 300 total points
ID: 24075020
Use this....
sw.WriteLine(vbTab & vbTab & vbTab & "Say(QuestGiver, " & Chr(34) & txtQuestAccSay.Text.Replace("(%)","GetName(Player)") & Chr(34) & Chr(41))

Open in new window

0
How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

 

Author Comment

by:Daniel112
ID: 24075057
Thank you both the reason why I got the expression error was because I was importing system.io.file when I should have not.

When I use either code that you guys gave me though it will output twice in the text file just like this:
 "Hello (%)"
 "Hello GetName(Player)"
How Would I get it to stop doubling again thank you.
0
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 300 total points
ID: 24075069
You are calling the sw.WriteLine method twice. Remove the superfluous line of code.

Wayne
0
 

Author Comment

by:Daniel112
ID: 24075101
Thank you so much. Sorry didn't see that I have so much code I should have looked.  Thank you again.
0
 

Author Closing Comment

by:Daniel112
ID: 31566902
Very Fast. Thank You Both!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 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