Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Read a string

Read a string

Scheduled Pinned Locked Moved Visual Basic
question
6 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad Fackrell
    wrote on last edited by
    #1

    Hi. I’m trying to write and if then statement that checks to see if a string contains a certain value. Here is how I thought it worked: If TheString.IndexOfAny(“This Text”) then I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Brad

    N S M 3 Replies Last reply
    0
    • B Brad Fackrell

      Hi. I’m trying to write and if then statement that checks to see if a string contains a certain value. Here is how I thought it worked: If TheString.IndexOfAny(“This Text”) then I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Brad

      N Offline
      N Offline
      Name Removed
      wrote on last edited by
      #2

      There is a function in Microsoft.VisualBasic called Instr that can, given two strings, give you the number of times that string2 occurs in string1. Try using this function Function ContainsStr(Str1 As String, Str2 as String) As Boolean Return (Microsoft.VisualBasic.Instr(Str1, Str2) > 0) End Function Hope This Helps

      B 1 Reply Last reply
      0
      • N Name Removed

        There is a function in Microsoft.VisualBasic called Instr that can, given two strings, give you the number of times that string2 occurs in string1. Try using this function Function ContainsStr(Str1 As String, Str2 as String) As Boolean Return (Microsoft.VisualBasic.Instr(Str1, Str2) > 0) End Function Hope This Helps

        B Offline
        B Offline
        Brad Fackrell
        wrote on last edited by
        #3

        This looks like it will do the trick. Thank you very much! Brad

        1 Reply Last reply
        0
        • B Brad Fackrell

          Hi. I’m trying to write and if then statement that checks to see if a string contains a certain value. Here is how I thought it worked: If TheString.IndexOfAny(“This Text”) then I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Brad

          S Offline
          S Offline
          shalwi
          wrote on last edited by
          #4

          i think it will work like this . if theString.IndexOfAny="This Text" then ROLI

          B 1 Reply Last reply
          0
          • S shalwi

            i think it will work like this . if theString.IndexOfAny="This Text" then ROLI

            B Offline
            B Offline
            Brad Fackrell
            wrote on last edited by
            #5

            Hi ROLI. I didn't completely understand the use of IndexOfAny. This thread contains a good explanation for anybody who is interested: http://www.visualbasicforum.com/showthread.php?t=175579 Thanks for you help. Brad

            1 Reply Last reply
            0
            • B Brad Fackrell

              Hi. I’m trying to write and if then statement that checks to see if a string contains a certain value. Here is how I thought it worked: If TheString.IndexOfAny(“This Text”) then I want the statement to return True if the string contains “This Text” anywhere within the string. Can anybody tell me how this should be written? Thanks Brad

              M Offline
              M Offline
              manish m tawde
              wrote on last edited by
              #6

              declare a boolean variable as say Dim val As boolean then after the statement, If TheString.IndexOfAny(“This Text”) then type val="true" Endif OR return "true":| u can then reference variable val elsewhere as the value returned

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups