ASCII Printable Characters Only
-
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
-
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
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
-
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
-
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
If you're using VB.NET, you can use the
IndexOfAny
method of theString
: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 IfIn 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 = FalseFor i = 1 To Len(s2)
index = InStr(1, s1, Mid(s2, i, 1)
If index > 0 Then
found = True
Exit For
End If
NextIf Not found Then
Debug.Print "Characters not found!"
Else
Debug.Print "Characters found at position " & index
End If