What a character !!
-
I have a string, oldWord, that contains exactly 1 space SOMEWHERE in it. I want to generate 26 copies of that word with the space being converted to a letter, 'a' through 'z'. I tried this: string oldWord; string[] newWord; ... for (int c = 0; c < 26; c++) { newWord[c] = oldWord.Replace(' ', 'a'+c ); } The compiler complains about the parameter, 'a'+c , as being an "invalid char", as you probably expected. I've tried lots of different combinations, to no avail. Would you please tell me how i can code that parameter so i get the expected result? Thank you.
-
I have a string, oldWord, that contains exactly 1 space SOMEWHERE in it. I want to generate 26 copies of that word with the space being converted to a letter, 'a' through 'z'. I tried this: string oldWord; string[] newWord; ... for (int c = 0; c < 26; c++) { newWord[c] = oldWord.Replace(' ', 'a'+c ); } The compiler complains about the parameter, 'a'+c , as being an "invalid char", as you probably expected. I've tried lots of different combinations, to no avail. Would you please tell me how i can code that parameter so i get the expected result? Thank you.
-
I have a string, oldWord, that contains exactly 1 space SOMEWHERE in it. I want to generate 26 copies of that word with the space being converted to a letter, 'a' through 'z'. I tried this: string oldWord; string[] newWord; ... for (int c = 0; c < 26; c++) { newWord[c] = oldWord.Replace(' ', 'a'+c ); } The compiler complains about the parameter, 'a'+c , as being an "invalid char", as you probably expected. I've tried lots of different combinations, to no avail. Would you please tell me how i can code that parameter so i get the expected result? Thank you.
Hi, You can also try this ...
string oldWord = "Hello Welcome"; string newWord = ""; for (int c = 0; c < 26; c++) { int newchar = (int)'a'+c; newWord += oldWord.Replace(' ', (char)newchar ); } System.Diagnostics.Debug.WriteLine(newWord);
Result:"HelloaWelcomeHellobWelcomeHellocWelcomeHellodWelcomeHelloeWelcomeHellofWelcomeHellogWelcomeHellohWelcomeHelloiWelcomeHellojWelcomeHellokWelcomeHellolWelcomeHellomWelcomeHellonWelcomeHellooWelcomeHellopWelcomeHelloqWelcomeHellorWelcomeHellosWelcomeHellotWelcomeHellouWelcomeHellovWelcomeHellowWelcomeHelloxWelcomeHelloyWelcomeHellozWelcome"
Happy Programming!!! :) Regards, P.Anbuselvan Sr.Software Engineer Hyderabad -
I have a string, oldWord, that contains exactly 1 space SOMEWHERE in it. I want to generate 26 copies of that word with the space being converted to a letter, 'a' through 'z'. I tried this: string oldWord; string[] newWord; ... for (int c = 0; c < 26; c++) { newWord[c] = oldWord.Replace(' ', 'a'+c ); } The compiler complains about the parameter, 'a'+c , as being an "invalid char", as you probably expected. I've tried lots of different combinations, to no avail. Would you please tell me how i can code that parameter so i get the expected result? Thank you.
-
I have a string, oldWord, that contains exactly 1 space SOMEWHERE in it. I want to generate 26 copies of that word with the space being converted to a letter, 'a' through 'z'. I tried this: string oldWord; string[] newWord; ... for (int c = 0; c < 26; c++) { newWord[c] = oldWord.Replace(' ', 'a'+c ); } The compiler complains about the parameter, 'a'+c , as being an "invalid char", as you probably expected. I've tried lots of different combinations, to no avail. Would you please tell me how i can code that parameter so i get the expected result? Thank you.
Thank you ALL for the excellent suggestions. I tried the 1st 2 suggestions before the 3rd was made ... they both worked great ... PLUS i got the added benefit of learning how to 'cast'. Thanks again,