+ 9
How to solve this error?
I want change a char of a string but I am getting error. https://code.sololearn.com/c29mJ7Eapi3e/?ref=app I am not understanding why I am getting this error and how to solve this.Please help me. Thanks in advance.I am new in c#.
13 Réponses
+ 6
copy the string to char array,then u can change any character
ex:
string str = "any string";
char [] arr = str.ToCharArray();
arr[0] = 'P';
+ 6
The CS0200 error is caused when you try to assign a value to a variable that can only be read and not changed. To fix the CS0200 error you will need to find an alternative way of achieving the desired result.
Same thing from stackoverflow
https://stackoverflow.com/questions/22093976/property-or-indexer-string-thisint-cannot-be-assigned-to-its-read-only
+ 4
Samsil Arefeen try this
take out lines 21 and 22
replace with:
String x = a.Replace("e", "v");
Console.WriteLine(x);
This is similar to Java
String x = a.replaceAll("e","v");
The first letter "e" is what letter will be changed throughout the sentence and the all the "e"s will become "v"s
+ 3
char[ ] a = Console.ReadLine().ToArray();
a[2] = 'v';
Console.WriteLine(a);
+ 2
Additional resources might worth a read 👇
https://www.arclab.com/en/kb/csharp/replace-or-remove-char-in-string-by-index.html
https://stackoverflow.com/questions/6945255/c-sharp-replace-string-in-string
+ 1
string is read only
+ 1
string is immutable, it cannot be changed after it is created, you can only create a new copy with the desired changes.
0
So any other way to change a char of a string?
0
0
C# != C++
they are mutable in C++
0
It works Lily Mea .
Thanks everyone for all of your contribution and help.
0
Which error?
- 2
The body tag follows the head tag.
All visual-structural elements are contained within the body tag.
Headings, paragraphs, lists, quotes, images, and links are just a few of the elements that can be contained within the body tag