Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check if String Contains

    Hi All

    My code at the moment contains

    Code:
    Dim readout As String = stream.ReadToEnd
    lbloverall.Text = readout
    I want it to be like this however

    Code:
    Dim readout As String = stream.ReadToEnd
    
    <<code to check if string contains "available">>
    <<code to check if string contains "regthroughus">>
    <<code to check if string contains "regthroughothers">>
    
    <<IF String does contain "available THEN>>
    lbloverall.Text = "available"
    
    and so on
    and so on.....
    My question is how do I check the string (readout) and see if those words are in there to compile the if statements.

    Thanks

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Hey MISCHU,

    It's String.Contains(...). Here is a link: http://msdn.microsoft.com/en-us/libr...x1sa.aspx#Y399.

    p.s. This one you definitely could have Google'd

    Mike

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    50
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Make search on string

    You could iterate trough the string's array and check your condition:


    Code:
    Foreach str as string in readout.Split("separator")
    {
    
    if(str.contains("available") || str.contains("available") || str.contains("available") 
    // Sequence
    )
    
    }
    if Contains doesn't fit your need try equals.

  • #4
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Regex might be a good coding exercise if everything else fails. Use Contains for faster task completion though.

  • #5
    New Coder
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    103
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Hi,

    Take input in array and iterate through each one by one and check for the string in current item of current iteration. Use contains() method.

  • #7
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, just use string.Contains and then you can specify if to ignore case


    ___________________________________________________
    http://makeflashgame.blogspot.com

  • #8
    Regular Coder
    Join Date
    Sep 2011
    Posts
    103
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Quote Originally Posted by MISCHU View Post
    Hi All

    My code at the moment contains

    Code:
    Dim readout As String = stream.ReadToEnd
    lbloverall.Text = readout
    I want it to be like this however

    Code:
    Dim readout As String = stream.ReadToEnd
    
    <<code to check if string contains "available">>
    <<code to check if string contains "regthroughus">>
    <<code to check if string contains "regthroughothers">>
    
    <<IF String does contain "available THEN>>
    lbloverall.Text = "available"
    
    and so on
    and so on.....
    My question is how do I check the string (readout) and see if those words are in there to compile the if statements.

    Thanks
    Hello,

    The method for this is
    If (string.contiains("")
    {
    }
    else
    {
    }

    Thanks,


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •