Friday, 13 August 2010

Being my first entry for over a week and also my first since returning from holiday, I'd though I would do a nice and easy one on this Friday afternoon and demonstrate the switch and case statement in VB.Net and C#....

Firstly, it is important to remember that the case identities correspond to the value's given from the drop down menu or listbox etc....

Ok the code for use in VB.Net is....

Select Case ListBox1.SelectedValue

Case 1
Case 2
Case 3
End Select

and for C# it's...

switch (DropDownList1.SelectedValue)

{ case "1":
case "2":

case "3":


Tuesday, 3 August 2010

How to Capitalize the First Letter of Every Word in a String

Neat little bit of coding to help anyone capitalize or make upper case the first letter of every word in a string. Quite handy this little script as first it will make sure that all letters in the string are formatted correctly...

So in VB.Net we have :

in the page load

Dim objconvertText As convertText
objconvertText = New convertText
MsgBox(objconvertText.convert("CAPITALIZE THIS!"))

and for the class

Public Function convert(ByVal theWord As String)
Dim capitalWord
capitalWord = LCase(theWord)
capitalWord = StrConv(capitalWord, VbStrConv.ProperCase)
Return capitalWord.ToString
End Function

and the same in C# is in the page load:

MessageBox.Show(convertTextFirst.capitalText("CAPITALIZE THIS!"));

and then in a class :

public static string capitalText(string theWord)
{string capitalWord;
capitalWord= theWord.ToLower();
capitalWord = char.ToUpper(capitalWord[0]) + capitalWord.Substring(1);
return capitalWord.ToString(); }

Calculating the Length of a String

Simple little one again for a Tuesday afternoon. A quick little demonstration on how to calculate the length of a string :

in c#

string test_string;
int value;
test_string = "George";
value = test_string.Length;
length.Text = value.ToString();

and also in

Dim test_string As String
Dim value As Integer
test_string = "George"
value = Len(test_string)
length.Text = value

and finally in PHP:

$howlong="how long is my string including spaces";
echo "The length of the string is : ".strlen($howlong);