![]() |
| | #1 |
| Registered User Join Date: Jan 2007
Posts: 188
| Edit string problem Im trying to replace one char in my string with another one. Obviously i don't know what's wrong because then i would fix it. :P W/e, here's my code: Code: textBox4.Text[Convert.ToInt32(var)] = Convert.ToChar(var); Code: Error 1 Property or indexer 'string.this[int]' cannot be assigned to -- it is read only C:\Users\HP-användare\Documents\Visual Studio 2008\Projects\Hangman\Hangman\Form1.cs 132 17 Hangman |
| Livijn is offline | |
| | #2 |
| Registered User Join Date: Jan 2007
Posts: 188
| I've googled it many times, but i can't find the answer. I can give you all the information about the code, just tell me. |
| Livijn is offline | |
| | #3 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,125
| Strings are immutable so you can't manually assign individual characters as you can in say C++. Look up the string methods Replace/Remove/Insert as they may be what you seek.
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #4 |
| Registered User Join Date: Jan 2007
Posts: 188
| Thanks for your help! |
| Livijn is offline | |
| | #5 |
| Registered User Join Date: Feb 2008
Posts: 74
| Code: /*########################################*/
/*########################################*/
/*########################################*/
private String String_Replace(String strText, String strFind, String strReplace)
{
try
{
int iPos = strText.IndexOf(strFind, System.StringComparison.CurrentCultureIgnoreCase);
String strReturn = "";
while (iPos != -1)
{
strReturn += strText.Substring(0, iPos) + strReplace;
strText = strText.Substring(iPos + strFind.Length);
iPos = strText.IndexOf(strFind);
}
if (strText.Length > 0) strReturn += strText;
return strReturn;
}
catch
{
return strText;
}
}
/*########################################*/
/*########################################*/
/*########################################*/
hm, You could I guess split your string into an array of bytes, replace your char there and then put it back together building a string. |
| AloneInTheDark is offline | |
| | #6 |
| Registered User Join Date: Jan 2007
Posts: 188
| Got a question... How can i store a word so i can get it from all classes? This doesn't work, but you might understand what i want. Code: public struct holder
{
int io;
}
public class save()
{
holder save = new holder;
save.io = 1;
}
public class print()
{
holder print = new holder;
if (print.io != 1)
{
//true
}
}
|
| Livijn is offline | |
| | #7 |
| Registered User Join Date: Feb 2008
Posts: 74
| If you need to reach a variable from outside a class, you do it as "public ..." , if not "private ..." Code: public class MyClass(){
public string ThisVariableCanBeReached;
private string ThisVariableCanNOTbeReached;
}
MyClass TEST = new MyClass(); TEST.ThisVariableCanBeReached = "bla bla"; If you need something which "doesn't change", try "public const" public const string ThisCanNotBeChanged = "Can't touch this!"; |
| AloneInTheDark is offline | |
| | #8 |
| Registered User Join Date: Jan 2007
Posts: 188
| When i try public const string... i get an error: Code: Error 1 Member 'Hangman.Form1.holder.word' cannot be accessed with an instance reference; qualify it with a type name instead C:\Users\HP-användare\Documents\Visual Studio 2008\Projects\Hangman\Hangman\Form1.cs 71 37 Hangman |
| Livijn is offline | |
| | #9 |
| Registered User Join Date: Feb 2008
Posts: 74
| Show me the code, not that weird long error without a line break in it! |
| AloneInTheDark is offline | |
| | #10 |
| Registered User Join Date: Jan 2007
Posts: 188
| Well since my computer crashed, it will take a while before... I must recode all! |
| Livijn is offline | |
| | #11 | |
| Registered User Join Date: Feb 2008
Posts: 74
| Quote:
Dude, ever heard of BACKUPS ? DVDs? External Drives? Don't tell me you formatted your drive and "lost" everything! hahahha... god damn it, my stomac hurts from the laugh. | |
| AloneInTheDark is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Inheritance Hierarchy for a Package class | twickre | C++ Programming | 7 | 12-08-2007 04:13 PM |
| string problem | INeedSleep | C++ Programming | 24 | 11-08-2007 11:52 PM |
| Program using classes - keeps crashing | webren | C++ Programming | 4 | 09-16-2005 03:58 PM |
| string pattern search problem | goron350 | C Programming | 6 | 11-25-2004 08:50 AM |
| Edit Control problem | Malek | Windows Programming | 3 | 06-16-2002 01:12 AM |