Web Analytics Made Easy -
StatCounter Check if String Contains - CodingForum

Announcement

Collapse
No announcement yet.

Check if String Contains

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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

    Comment


    • #3
      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.
      Don't forget to mark solution providing post as "Answered".
      It helps others to find correct solutions!

      Comment


      • #4
        Regex might be a good coding exercise if everything else fails. Use Contains for faster task completion though.

        Comment


        • #5
          try string.contains();

          The C# Contains method returns true if and only if this string contains the specified sequence of char values.


          rbt.

          Comment


          • #6
            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.

            Comment


            • #7
              Yes, just use string.Contains and then you can specify if to ignore case


              ___________________________________________________
              http://makeflashgame.blogspot.com

              Comment


              • #8
                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,

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎