-1

I am trying to delete the 3rd and 4th character from a string from a value from a database which has a serialized data, for below example i need to remove the number 2 and 3, i am using below code to remove the first character from a string, since the replace method needs to find a specific character then replace it with, but below string is unique, i think the method that i am looking for is remove.

00230A01E0

Removing the first character

String data = '00230A01E0';
data.Remove(0,1);

So the final output will look like this

000A01E0
KaoriYui
  • 912
  • 1
  • 13
  • 43
  • 1
    This question is just a duplicate of all the other "I can't get the string-mutating methods to work" questions that already exist on Stack Overflow. See e.g. [this answer](https://stackoverflow.com/a/43387831) – Peter Duniho May 24 '17 at 06:21

1 Answers1

3

Strings are immutable, so such functions will always return a new string.

Try

data = data.Remove(2, 2);

i.e. go to index 2 (character 3) and remove 2 characters.

In future, I highly recommend checking the functions on MSDN before posting here, since the documentation clearly states that a new string is returned.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86