1

How would i go about deleting (not just replacing with a ' ') The nth char of a string. Say i want to have Hello World output Hllo World any thing that could do this?

  • 3
    Two substrings (one of all characters before the one you wish to delete, the other of characters after) and then you concatenate them. – TheZ Nov 28 '12 at 21:46
  • Possible Duplicate: [Replacing a char at a given index in string?](http://stackoverflow.com/q/9367119/299327) – Ryan Gates Nov 28 '12 at 21:56
  • check out my answer its better and cooler and youll look cooler using linq than with using the built in String.Remove function ;) – jordan Nov 28 '12 at 22:16
  • @jordan.peoples: Your approach is clumsier and slower than the builtin `String.Remove`. Ryan, that is not a duplicate. How could a question "not replacing in string" be a duplicate of "replacing char in string"? – Tim Schmelter Nov 28 '12 at 22:52
  • there's no way its slower. may take more space and more screen real estate, but looks cooler and is more flexible for a wider range of applications @TimSchmelter Also, try to keep it professional. saying "Are you kidding?" gets a flagged comment. – jordan Nov 28 '12 at 22:55
  • @jordan.peoples: Removed the "kidding" but again, looks cooler is no value and multiple lines that create many intermediate strings instead of one efficient method is not _cooler_ but just redundant. – Tim Schmelter Nov 28 '12 at 22:58
  • @TimSchmelter Possibilities my dear tim, possibilities. – jordan Nov 28 '12 at 23:06
  • @jordan.peoples: You can downvote all of my answers and questions if you want, that won't make your answer more useful at all. – Tim Schmelter Nov 28 '12 at 23:11
  • @TimSchmelter who down voted what now? i got a down vote for my awesome answer. – jordan Nov 28 '12 at 23:24
  • 1
    @TimSchmelter, Don't worry, he went on a downvote campaign against me recently after he complained about downvotes on a horrible answer. A few days later they were all reversed. It's not worth arguing with him. He won't see sense and he gets childishly defensive. – TheEvilPenguin Nov 29 '12 at 01:05

3 Answers3

8

With .Remove

var removed = s.Remove(1, 1);

note, you can't change a string, you can only create a new string with the character removed.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
2

String class has a remove method

var s = "abc".Remove(1,1); //will return ac 
L.B
  • 114,136
  • 19
  • 178
  • 224
0
StringBuilder a = new StringBuilder("Hello World");
a.remove(1, 1);
bhuang3
  • 3,493
  • 2
  • 17
  • 17