Remove single character from a string?

20.1k views Asked by At

How would you remove a single character from a string?

string = string.Remove(3);

but it removes the third char and everything else.

4

There are 4 answers

1
B Faley On BEST ANSWER

According to the remove method signature:

public string Remove(
    int startIndex,
    int count
)

you need to provide a second parameter as the total number of characters to remove from startIndex:

string = string.Remove(3, 1);
0
SLaks On
0
Al Kepp On

string = string.Remove(3,1);

0
T Jose On

Speaking theory, String.Remove() "does not" remove anything as strings are immutable. In the background it creates a new instance of string with the character(s) removed.

But, for the purpose you mentioned you can use String.Remove(3,1) to remove a single character.