By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,862 Members | 1,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,862 IT Pros & Developers. It's quick & easy.

Searching for Specific Characters

P: 3
How can I search for a specific character within a string?
For example say I want to search for the letter "n"
and the string is "peanut"- How can search for it so I can remove the n?
For example- If the letter n is found- it is removed. So
Searching for "n"
Word "peanuts"
Word is found
Turns to "peauts"
Jan 18 '14 #1

✓ answered by Rabbit

You can use the replace function to that end.

Share this Question
Share on Google+
6 Replies

Expert Mod 10K+
P: 12,406
You can use the replace function to that end.
Jan 18 '14 #2

P: 300
Rabbit is right. Here's a very simple example to work from:
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = TextBox1.Text.Replace("n", "")
Jan 20 '14 #3

P: 3
But when I do that, it replaces all characters before the letter- and how will I replace the same letters?
There are two e's how do I replace only one?
Nvm I can determine what position it replaces from- but it still deletes all characters before.
Jan 24 '14 #4

Expert Mod 10K+
P: 12,406
I don't know what you're talking about when you say "replacing the characters before".

And this is the first time you mentioned that you only want to replace the first occurrence.

You didn't mention any of this in your original post, you will need to explain in more detail.
Jan 24 '14 #5

P: 3
I found some difficulties while replacing some characters.
This is how Replace works:
replace(word, letter, replacement4letter, position, howmanyiwanttoreplace)
So if I have:
Textbox1.text = "-----"
When Button1 is clicked: Textbox1.text = replace(textbox1.text, "-", "a", 2, 1)
And in the end Textbox1.text becomes = "a---"
How do I make it so the letters before the position is not deleted? I want it so when button 1 is clicked I want textbox1.text to be "-a---", not "a---".
I hope I explained clearly
Jan 25 '14 #6

Expert Mod 10K+
P: 12,406
In that case, you can substring out the beginning of the string, and append the replace result to that.
Jan 26 '14 #7

Post your reply

Sign in to post your reply or Sign up for a free account.