vendredi 27 mars 2015

How can string.replace remove indexes from a string

This might be a duplicate question, but a quick search did not give me any results.


So this is probably just a technical quesiton and I'm kind of curious. First off I'm working in C# but I imagine this works in a lot of other languages too.


So as I've learned it, a string is an array of characters but with it's own name to make it a little easier.


When you have a string and want to remove a part of the string you can do it like this.



string test = "0123456789";
test = test.Replace("789","");


This not just replaces the value of the indexes at those points of the string to nothing but removes the index from the string (character array) all together. When I try to set the indexes of a string array like.



string[] testa = {'1', '2','3','4'};
testa[3] = "";


The length of the array stays the same and the indexes are still there.


When you try the same thing on an actual character array you get a sintax error. eg.



char[] testa = {'1', '2','3','4'};
testa[3] = '';


or



testa[3] = "";


So... What's happening here and how does it work.


Aucun commentaire:

Enregistrer un commentaire