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. ASCII Printable Characters Only

ASCII Printable Characters Only

Scheduled Pinned Locked Moved Visual Basic
data-structureshelpquestion
4 Posts 3 Posters 0 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.
  • L Offline
    L Offline
    Like2Byte
    wrote on last edited by
    #1

    Hello again, C has a function called 'strpbrk,' which stands for string point break. The function takes two arguments. First arg is the string I want to search. The second arg is a string of characters that I want to check for. If any of the characters contained in the second string are in the first string the function returns a pointer to the element in the array where the character was located. Basically, if none of the characters in the second set are found in the first set, the function returns NULL (or zero, if you will). Does VB have a function that performs this same operation? my func: [source] ' forgive my C-speak if strpbrk( "HELP ME, PLEASE!", " SXPT" ) //character ' ' found (space) // do something printf("Characters found in set!"); else //characters in second set NOT found in first set // do something else printf("Characters NOT found in set!"); [/source] or Do I have to use an array and scroll through the entire array to accomplish this? Thanks in advance, Like2Byte

    D Richard DeemingR 2 Replies Last reply
    0
    • L Like2Byte

      Hello again, C has a function called 'strpbrk,' which stands for string point break. The function takes two arguments. First arg is the string I want to search. The second arg is a string of characters that I want to check for. If any of the characters contained in the second string are in the first string the function returns a pointer to the element in the array where the character was located. Basically, if none of the characters in the second set are found in the first set, the function returns NULL (or zero, if you will). Does VB have a function that performs this same operation? my func: [source] ' forgive my C-speak if strpbrk( "HELP ME, PLEASE!", " SXPT" ) //character ' ' found (space) // do something printf("Characters found in set!"); else //characters in second set NOT found in first set // do something else printf("Characters NOT found in set!"); [/source] or Do I have to use an array and scroll through the entire array to accomplish this? Thanks in advance, Like2Byte

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      Like2Byte wrote: Do I have to use an array and scroll through the entire array to accomplish this? Yes My latest articles: XOR tricks for RAID data protection Win32 process suspend/resume tool

      L 1 Reply Last reply
      0
      • D Daniel Turini

        Like2Byte wrote: Do I have to use an array and scroll through the entire array to accomplish this? Yes My latest articles: XOR tricks for RAID data protection Win32 process suspend/resume tool

        L Offline
        L Offline
        Like2Byte
        wrote on last edited by
        #3

        Thanks, here's what I did. dim c as string dim s as string dim i as long s = "really long string really long string really long string..." for i = 1 to len(s) c = mid$(s, i, 1) select case asc(c) case 1 to 127 ' do stuff end case next

        1 Reply Last reply
        0
        • L Like2Byte

          Hello again, C has a function called 'strpbrk,' which stands for string point break. The function takes two arguments. First arg is the string I want to search. The second arg is a string of characters that I want to check for. If any of the characters contained in the second string are in the first string the function returns a pointer to the element in the array where the character was located. Basically, if none of the characters in the second set are found in the first set, the function returns NULL (or zero, if you will). Does VB have a function that performs this same operation? my func: [source] ' forgive my C-speak if strpbrk( "HELP ME, PLEASE!", " SXPT" ) //character ' ' found (space) // do something printf("Characters found in set!"); else //characters in second set NOT found in first set // do something else printf("Characters NOT found in set!"); [/source] or Do I have to use an array and scroll through the entire array to accomplish this? Thanks in advance, Like2Byte

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          If you're using VB.NET, you can use the IndexOfAny method of the String:

          C#:
          string s1 = "HELP ME, PLEASE!";
          string s2 = " SXPT";
          int i = s1.IndexOfAny(s2.ToCharArray());
          if (i == -1)
          Console.WriteLine("Characters not found!");
          else
          Console.WriteLine("Characters found at position {0}", i);

          VB.NET:
          Dim s1 As String = "HELP ME, PLEASE!"
          Dim s2 As String = " SXPT"
          Dim i As Integer = s1.IndexOfAny(s2.ToCharArray())
          If i = -1 Then
          Console.WriteLine("Characters not found!")
          Else
          Console.WriteLine("Characters found at position {0}", i)
          End If

          In VB6, you would have to fake it:

          Dim s1 As String : s1 = "HELP ME, PLEASE!"
          Dim s2 As String : s2 = " SXPT"
          Dim i As Integer
          Dim index As Integer
          Dim found As Boolean : found = False

          For i = 1 To Len(s2)
          index = InStr(1, s1, Mid(s2, i, 1)
          If index > 0 Then
          found = True
          Exit For
          End If
          Next

          If Not found Then
          Debug.Print "Characters not found!"
          Else
          Debug.Print "Characters found at position " & index
          End If

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          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