Jerry Grey Member Posted August 14, 2004 Member Share Posted August 14, 2004 Hey, I am trying to get this code to work, but it doesn't want to work. label.Text.Replace("Loading...", "Ready to Go!!") Thanks :D Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 14, 2004 Share Posted August 14, 2004 Why not just set label.Text = "Ready to Go!!"? Link to comment Share on other sites More sharing options...
0 Winston Posted August 14, 2004 Share Posted August 14, 2004 Of course it doesnt work, what's the text in your label right now? it has to correspond to whatever text you specify to replace, and as weenur said, just assign the text property a new value. Link to comment Share on other sites More sharing options...
0 Jerry Grey Member Posted August 14, 2004 Author Member Share Posted August 14, 2004 LOL :blush: Why didn't I think of that... :rolleyes: Thanks Weenur :D Link to comment Share on other sites More sharing options...
0 itsnotabigtruck Posted August 14, 2004 Share Posted August 14, 2004 Hey,I am trying to get this code to work, but it doesn't want to work. label.Text.Replace("Loading...", "Ready to Go!!") Thanks :D That command performs a find and replace operation on the string 'label.Text' and returns the result. You are discarding the return value, and even if you used the result, it would be very inefficient. Instead, to change the text of a label, set label.Text to the string literal "Ready to Go!!". label.Text = "Ready to Go!!" If you want to perform a find and replace operation, you would use your current code. But for god's sake, use the return value! For example, this code... Dim s As String = "tonsOfText-tonsOfText-tonsOfText" s = s.Replace("Text", "Stuff") MsgBox(s) ...would cause a messagebox to appear saying "tonsOfStuff-tonsOfStuff-tonsOfStuff". BTW: A string is a series of text and a variable type. A string literal is a string defined in code without using a variable. Link to comment Share on other sites More sharing options...
0 Jerry Grey Member Posted August 14, 2004 Author Member Share Posted August 14, 2004 Thanks for explaning it :D Link to comment Share on other sites More sharing options...
0 Winston Posted August 14, 2004 Share Posted August 14, 2004 BTW: A string is a series of text and a variable type. A string literal is a string defined in code without using a variable. Isn't it an array of chars? Link to comment Share on other sites More sharing options...
0 itsnotabigtruck Posted August 14, 2004 Share Posted August 14, 2004 Isn't it an array of chars? Nope. Dim s As String <-- string s = "string literal" <-- string literal Dim s As String() <-- string array Dim s As String() = {"string", "literal", "array"} <-- string array instantiated with an array of string literals Dim c As Char <-- character c = "c"c <-- character Dim c As Char() <-- character array Dim c As Char() = {"c"c, "h"c, "a"c, "r"c, " "c, "a"c, "r"c, "r"c, "a"c, "y"c} <-- character array instantiated with an array of characters c is the type character for the Char type. That is required under Option Strict. http://www.python.org/doc/current/ref/strings.html <-- never mind that it is Python, it defines a string literal as a string defined in code using double quotes (or single quotes in Python) Link to comment Share on other sites More sharing options...
0 John Veteran Posted August 14, 2004 Veteran Share Posted August 14, 2004 Isn't it an array of chars? Nope. System.String.ToCharArray() returns an array of characters ;) Link to comment Share on other sites More sharing options...
0 Winston Posted August 14, 2004 Share Posted August 14, 2004 Oh i was saying isn't a String made up of an array of chars, that's what i mean... Link to comment Share on other sites More sharing options...
0 John Veteran Posted August 14, 2004 Veteran Share Posted August 14, 2004 Oh i was saying isn't a String made up of an array of chars, that's what i mean... In C/C++, yes. But not in .NET ;) At least try not to think of it that way, because the String object doesn't really behave like a character array, even though internally, it very well could be an array of characters... Link to comment Share on other sites More sharing options...
0 itsnotabigtruck Posted August 15, 2004 Share Posted August 15, 2004 Nope. System.String.ToCharArray() returns an array of characters ;) Hmm. Didn't know that. :D Link to comment Share on other sites More sharing options...
Question
Jerry Grey Member
Hey,
I am trying to get this code to work, but it doesn't want to work.
label.Text.Replace("Loading...", "Ready to Go!!")Thanks :D
Link to comment
Share on other sites
11 answers to this question
Recommended Posts