Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Trim out individual values from a comma separated ...
Author:
Mesrop Simonian
E-mail:
Click to e-mail author
Submitted:
10/16/2002
Version:
VB5
Compatibility:
VB5, VB6
Category:
String Manipulation
Views:
12787
Trim out individual values from a comma separated string.
Declarations:
'none
Code:
Function CountCSString(ByVal s) As Integer 'Counts the words in a comma separated string. Dim WC As Integer, Pos As Integer If VarType(s) <> 8 Or Len(s) = 0 Then CountCSString = 0 Exit Function End If WC = 1 Pos = InStr(s, ",") Do While Pos > 0 WC = WC + 1 Pos = InStr(Pos + 1, s, ",") Loop CountCSString = WC End Function Function GetCSString(ByVal s, Indx As Integer) 'Returns the nth word in a specific field. Dim WC As Integer, Count As Integer Dim SPos As Integer, EPos As Integer WC = CountCSString(s) If Indx < 1 Or Indx > WC Then GetCSWord = Null Exit Function End If Count = 1 SPos = 1 For Count = 2 To Indx SPos = InStr(SPos, s, ",") + 1 Next Count EPos = InStr(SPos, s, ",") - 1 If EPos <= 0 Then EPos = Len(s) GetCSString = Trim(Mid(s, SPos, EPos - SPos + 1)) End Function Private Sub Test() Dim strAString As String Dim I As Integer Dim intCnt As Integer strAString = "union1,union2,union3,union4,union5,union6,union7" 'Find out how many comma separated words 'are present intCnt = CountCSString(strAString) MsgBox intCnt 'Now call the other function to retrieve each one in turn For I = 1 To intCnt MsgBox GetCSString(strAString, I) Next End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement