Click here to Skip to main content
15,914,905 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I miss my string[i] = 'x' :( Pin
RugbyLeague18-Sep-16 21:54
RugbyLeague18-Sep-16 21:54 
GeneralRe: I miss my string[i] = 'x' :( Pin
TheGreatAndPowerfulOz18-Sep-16 18:11
TheGreatAndPowerfulOz18-Sep-16 18:11 
GeneralRe: I miss my string[i] = 'x' :( Pin
raddevus18-Sep-16 18:24
mvaraddevus18-Sep-16 18:24 
GeneralRe: I miss my string[i] = 'x' :( Pin
#realJSOP19-Sep-16 0:05
professional#realJSOP19-Sep-16 0:05 
GeneralRe: I miss my string[i] = 'x' :( Pin
Chris Maunder19-Sep-16 3:27
cofounderChris Maunder19-Sep-16 3:27 
GeneralRe: I miss my string[i] = 'x' :( Pin
TheGreatAndPowerfulOz19-Sep-16 4:15
TheGreatAndPowerfulOz19-Sep-16 4:15 
QuestionRe: I miss my string[i] = 'x' :( Pin
Maciej Los30-Sep-16 10:13
mveMaciej Los30-Sep-16 10:13 
GeneralRe: I miss my string[i] = 'x' :( Pin
BillWoodruff18-Sep-16 23:06
professionalBillWoodruff18-Sep-16 23:06 
If that were possible in C#, wouldn't that "weaken" the (what I perceive as) intention of the language designers to enforce string immutability ?

Sure, you can do a work-around using Extension Methods. Visual Basic allows you pass the 'this parameter of an Extension Method by reference, while C# does not, so something like this will do:
C#
public static string SetChar(this string str, int ndx, char ch)
{
    if(ndx >= str.Length) throw new ArgumentOutOfRangeException();

    charAry = str.ToCharArray();
    charAry.SetValue(ch,ndx);
    return new string(charAry);
}
I used a 'CharArray here simply because TheGreatAndPowerfulOz already mentioned using StringBuilder.

However, you could write an Extension Method on 'Char, and pass the string by reference, but that syntax would look kind of weird: string somesubstitution = 'x'.SetCharInto(ref mystringVar, 3);

Gosh, I wish I CodeProject had a Forum where a lot of people really discussed C# language issues ! In case that statement is not clear to some of you: I am indirectly lamenting the fact that the C# language forum is now not what it was many years ago in terms of real interchanges about language features, often, imho, full of questions that should have been posted on the QA forums.

cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

GeneralRe: I miss my string[i] = 'x' :( Pin
#realJSOP19-Sep-16 1:27
professional#realJSOP19-Sep-16 1:27 
GeneralRe: I miss my string[i] = 'x' :( Pin
BillWoodruff19-Sep-16 2:17
professionalBillWoodruff19-Sep-16 2:17 
GeneralRe: I miss my string[i] = 'x' :( Pin
#realJSOP19-Sep-16 2:26
professional#realJSOP19-Sep-16 2:26 
GeneralRe: I miss my string[i] = 'x' :( Pin
BillWoodruff19-Sep-16 2:57
professionalBillWoodruff19-Sep-16 2:57 
GeneralRe: I miss my string[i] = 'x' :( Pin
Chris Maunder19-Sep-16 3:30
cofounderChris Maunder19-Sep-16 3:30 
GeneralRe: I miss my string[i] = 'x' :( Pin
BillWoodruff19-Sep-16 8:49
professionalBillWoodruff19-Sep-16 8:49 
JokeRe: I miss my string[i] = 'x' :( Pin
Richard Deeming19-Sep-16 2:54
mveRichard Deeming19-Sep-16 2:54 
RantThis Is How Android Wins! Android Dev v Windows Dev PinPopular
raddevus18-Sep-16 12:21
mvaraddevus18-Sep-16 12:21 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
Henry Skoglund18-Sep-16 12:54
Henry Skoglund18-Sep-16 12:54 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
raddevus18-Sep-16 13:06
mvaraddevus18-Sep-16 13:06 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
Henry Skoglund18-Sep-16 15:09
Henry Skoglund18-Sep-16 15:09 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
User 483504718-Sep-16 15:12
User 483504718-Sep-16 15:12 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
wout de zeeuw18-Sep-16 15:24
wout de zeeuw18-Sep-16 15:24 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
raddevus18-Sep-16 15:35
mvaraddevus18-Sep-16 15:35 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
wout de zeeuw18-Sep-16 15:46
wout de zeeuw18-Sep-16 15:46 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
raddevus18-Sep-16 16:39
mvaraddevus18-Sep-16 16:39 
GeneralRe: This Is How Android Wins! Android Dev v Windows Dev Pin
Super Lloyd18-Sep-16 15:34
Super Lloyd18-Sep-16 15:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.