By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 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


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

100+
P: 299
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?
Example:
Word=Elephant
There are two e's how do I replace only one?
Edit:
Nvm I can determine what position it replaces from- but it still deletes all characters before.
Jan 24 '14 #4

Rabbit
Expert Mod 10K+
P: 12,347
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
Thx
Jan 25 '14 #6

Rabbit
Expert Mod 10K+
P: 12,347
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.