I am trying to convert something to all upercase. I thought it was just Convert.ToUpper(textbox1.Text) but it doesn't appear to be the case.
cmdInsert.Parameters.Add( "@dotnet.itags.org.P_name_first", Convert.ToUpper(name_first_input.Text) );
I am using parameters because this is going to go into an SQL database. Does anyone have a recomendation on how i convert the text in name_first_input to all upercase?
ThanksSimple:
cmdInsert.Parameters.Add( "@.P_name_first", name_first_input.Text.ToUpper() );
Does the call to the method always come after to the .Text or.. w/e you are using?
I thought it was ToUpper(name_first_input.Text)?
What i meant to say on the last one was..
To you (what do you call this.. reference) to a method, whether it be ToString, to Int32..
after your variable?
Like if you were converting an Int to a string, would it be
int a = Convert.ToInt32(number.Text);
or would it be
int a = number.Text.ToInt32();
Thanks for the help :)
String.ToUpper() is simply a member of the string class.
So,anything that is of the type string can have this method applied to it.
For example:
string s1 = "hello world";
string s2 = s1.ToUpper();string s3 = ("hello").ToUpper() + (" world").ToUpper();
string s4 = myTextbox.Text.ToUpper();
string s5 = System.DateTime.Now.ToString().ToUpper();
string s6 = MyCustomObject.ToString().ToUpper()
string s7 = ((string)HttpContext.Current.Items["user"]).ToUpper();
Does this help?
I think so :) I'm just looking for the order that you write code in.. Do members of classes come after the values?
Thanks :D
> Do members of classes come after the values?
With object-oriented programming, it helps to think about objects rather than values or variables.
Take for example the following:
string userName = "daffy duck";If you think of userName as being a variable, it is harder to think about what we can do with it. I mean, how on earth can we possibly know whether we can perform .ToUpper() on it?
If instead you think of userName as being a string object, it is easier to think about what we can do with it.Because it is a string, we can performany of the string methods on it, and we can grabany of the string properties from it.
string userName = "daffy duck";
string userNameKey = userName.ToUpper();
Taking another example:
DateTime rightNow = DateTime.Now;Again, if you think about rightNow as being a variable, you'd reasonably wonder why you cannot do the same actions on rightNow as you could with userName.
However, if you think about rightNow as being a DateTime object, it gets easier. Because it is a DateTime object, we can performany of the DateTime methods on it, and we can get any of the DateTime properties from it. No more, and no less.
DateTime rightNow = DateTime.Now;We can do the above easilybecause rightNow is a DateTime object.
DateTime tomorrow = rightNow.AddDays(1);
Now, let's say you wanted to grab an upper-case value of tommorow's date. The documentation for DateTime tells us that it does not have a ToUpper() function. Phooey. Yet, we know that a string objectdoes have a ToUpper() function.
Knowing this, wefirst create a string object, andthen perform ToUpper() on that string object.
DateTime rightNow = DateTime.Now;The above is unnecessarily complex. Let's simplify it.
DateTime tomorrow = rightNow.AddDays(1);
string tomorrowAsString = tomorrow.ToString();
string tomorrowInCaps = tomorrowAsString.ToUpper();
We only use rightNow a single time. Because of this, there's not much point in creating a new named object. Why not create a temporary object? The temporary object will be a DateTime object too, just without the name:
DateTime tomorrow = (DateTime.Now).AddDays(1);The bracketed (DateTime.Now) is a temporary DateTime object, just like rightNow was. It simply doesn't have a name.
string tomorrowAsString = tomorrow.ToString();
string tomorrowInCaps = tomorrowAsString.ToUpper();
We only use tomorrow in order to get tomorrowAsString. So we can simplify our code further:
string tomorrowAsString = ((DateTime.Now).AddDays(1)).ToString();Again, (DateTime.Now) was a temporary object of type DateTime. We then use a method of this temporary object to give us a second temporary object, again of type DateTime. This was ((DateTime.Now).AddDays(1)). On this second temporary DateTime object, we used the ToString() method.
string tomorrowInCaps = tomorrowAsString.ToUpper();
We only use tomorrowAsString once, too. Again, why not make this a temporary object, rather than a named object?
string tomorrowInCaps = (((DateTime.Now).AddDays(1)).ToString()).ToUpper();If you use the brackets as a way of distinguishing the temporary objects, you'll see that there are three temporary objects in there. In truth, I added the brackets as an aid to see the objects. We could instead have done:
string tomorrowInCaps = DateTime.Now.AddDays(1).ToString().ToUpper();This of course looks much cleaner. So why didn't I say that to start with? I used the brackets to show that even in the above line of code, three temporary objects are being created, two of type DateTime, and one of type string.
I don't know how well I explained this. But the point I am trying to make is that if you think about objects rather than variables, .NET should start making a lot more sense.
This reply is already too long, so I won't go into Parse methods and the Convert class. However, if you start thinking about objects rather than variables, then you may soon understand the Parse methods and the Convert class.
One day, I'm going to gather my longer replies and make them into articles :)
Man.. that is an awesome reply, as always :) Thanks much.. i got another interesting question coming in a minute :D
0 comments:
Post a Comment