Results 1 to 4 of 4
  1. #1
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed

    [Tutorial] String Manipulation

    Beginners Guide to Strings in VB.net
    Another Nextgen1 Article/Tutorial

    Note: as for all my tuts and articles , The best way to learn is to experience what you are trying to learn, So open up Vb.net and follow along, don't just copy and paste what is needed, your never going to learn that way.

    1. Length of a string (Variable)
    Add to your Form a Textbox, a Label and A button (don't worry to much about the properties of these, or how it looks on the form, this is not a guide to UI)

    To get the length of a string , we use .Length

    Here is an example code, add this to the Button Click Event

    Code:
        Label1.text = Textbox1.Text.Length
    Start the program, add some text to the TextBox and click the button. Your label should give you the length of the string or variable entered.

    2. Search using IndexOf

    Something everyone is looking to do every now and then is search text for a particular word programatically, In order to do this we will have to use the IndexOf (Find word, StartPosition) function.

    The IndexOf command returns its value as an integer at the place where it finds the string in the text.

    This code starts at the beginning of 'I like programming and writing tutorials', because we didn't give a start position, and searches for the word 'writing' in it.

    If it does not find the word "writing" in the string, then it will return the value as 0, and your label will say '0'. in which case you can use

    Code:
     
    If label1.text = 0 then msgbox ("Could not find the word you are looking for")
    ' You can be more advanced, but for simplicity reasons, im going to keep this    ' short
    However, if it finds the word, then it returns a number saying where it found the start of the word. In this case, your label should say '25'(I think I counted right) because the 'w' of the word writing is 25 characters into the string.

    Code:
        
        Dim S As String = "I like programming and writing tutorials"
        S = S.IndexOf("writing")
        Label1.text = S
    3. Replace Text or characters with another text or character.

    Next on our list of things to learn is .Replace which is used to find and replace text in a string.

    The Replace function returns the text that it has replaced.

    Code:
        Dim R As String = "I like programming"
        R = R.Replace("Like", "Love")
        LabelBox1.text = R

    4. UPPERCASE to lowercase

    This is useful for making sure that if a user types something in uppercase then it will still comply with something in your code that is lowercase. (very handy for a lot of applications)

    To make a sentence uppercase, you use the following:
    Code:
        Dim U as String
        U = "I love PROGRAMMING"
        U = *****Upper
        	
        Label1.text = U
    Label1 should now contain the words 'I LOVE PROGRAMMING'

    To convert to lowercase, use the following:

    Dim L as String
    L = "I love PROGRAMMING"
    L = L.ToLower

    Label1.text = L

    Label1.text should now contain the words 'i love programming'

    5. Reversing the order.

    At first I was not going to add this part to the tutorial because lack of use, however, I figured there may be someone who could use it, So I am sharing StrReverse

    If you wish to flip around a string, then the StrReverse(string) will do it

    Code:
        Label1.text=(StrReverse("I love programming"))
    You should get the result "gnimmargorp evol I"

    Well that basically covers a beginners Guide, If you request I will do a advanced guide containing 5 more string manipulation concepts and uses.

    Hope this helps those he need it
    Last edited by NextGen1; 01-19-2010 at 11:13 PM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  2. The Following 4 Users Say Thank You to NextGen1 For This Useful Post:

    Blubb1337 (01-26-2010),Lolland (01-19-2010),Nexulous (01-19-2010),Zoom (02-02-2010)

  3. #2
    Lolland's Avatar
    Join Date
    Feb 2009
    Gender
    male
    Location
    Lolland!
    Posts
    3,156
    Reputation
    49
    Thanks
    868
    My Mood
    Inspired
    You are a VBeast.

  4. #3
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Quote Originally Posted by lolland View Post
    You are a VBeast.
    Thanks again, and again a lot more to come, trying to keep vb section alive.

    Still want to get everyone together and make a killer MPGH.Net Suite Application.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  5. #4
    Nexulous's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    in dbb's vagina.
    Posts
    4,047
    Reputation
    63
    Thanks
    218
    My Mood
    Innocent
    Nice tut. For nubs, but nonetheless, nice.

Similar Threads

  1. In-depth Tutorial Comparing Strings
    By Shark23 in forum Assembly
    Replies: 5
    Last Post: 11-30-2010, 07:33 AM
  2. [Tutorial] String collections and settings. I think so.
    By Jason in forum Visual Basic Programming
    Replies: 18
    Last Post: 09-14-2010, 09:47 PM
  3. Tutorial Draw Strings
    By UnOwN CoD3R in forum Medal of Honor (MOH) Hacks
    Replies: 4
    Last Post: 09-10-2010, 04:47 AM
  4. Warrock Hack - Tutorial
    By Dave84311 in forum WarRock - International Hacks
    Replies: 667
    Last Post: 10-09-2007, 10:10 AM
  5. Photoshop Tutorials
    By Dave84311 in forum Art & Graphic Design
    Replies: 3
    Last Post: 12-31-2005, 07:21 AM