Find character and remove the character. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Find character and remove the character.

How to find 1 character like (. ) in 100 text file and remove it in c#

12th Apr 2017, 8:09 AM
prg_Mohamad
prg_Mohamad - avatar
5 Answers
+ 1
c# has regular expressions?
12th Apr 2017, 8:14 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
+ 1
why you can't use them in replace method/function?
12th Apr 2017, 8:18 AM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
+ 1
You can use stringName.indexOf('.') to find the first occurrence of '.' in you string and use that position in the next command. string.Remove(position,number of characters to remove) In c# a string is an array of chars so you can access individual characters with an index (just like you do with an array). For example in a word "Code" you can access letter "d" by writing word[2]. Keep in mind that the indexing starts from 0. If you want to remove a character on 100th position use stringName.Remove(100,1);
12th Apr 2017, 8:20 AM
Dextozz
Dextozz - avatar
+ 1
With regex would looks like -> /\./g then replace the match by nothing.
12th Apr 2017, 8:24 AM
Geoffrey L
Geoffrey L - avatar
0
Yes
12th Apr 2017, 8:16 AM
prg_Mohamad
prg_Mohamad - avatar