Author | Message | Time |
---|---|---|
Atom | I thought that this may be useful to some of you developers out there. This is a replacement for the "Split" Function in vb. It splits by Spaces except when the spaces are inside quotes. It also ignores double spaces outside of quotes. Im using this for some custom commands but im sure some of you might find it useful for some other purpose. (It would be good for a simple protocol). [code] Public Function Seperate(strCode As String) As Variant '''By Atom''' Dim arrTemp() As Variant, strTemp As String, i As Integer, x As Integer Dim LastChar As String, Char As String, inQuotes As Boolean For i = 1 To Len(strCode) LastChar = Char Char = Mid(strCode, i, 1) If inQuotes = False Then If Char = " " Then If LastChar <> " " Then strTemp = strTemp & Char End If Else strTemp = strTemp & Char If Char = Chr(34) Then inQuotes = True End If Else strTemp = strTemp & Char If Char = Chr(34) Then inQuotes = False End If Next i If Left(strTemp, 1) = " " Then strTemp = Mid(strTemp, 2) If Right(strTemp, 1) = " " Then strTemp = Left(strTemp, Len(strTemp) - 1) inQuotes = False ReDim Preserve arrTemp(0) x = 0 For i = 1 To Len(strTemp) Char = Mid(strTemp, i, 1) If Char = " " Then If inQuotes = False Then x = x + 1 ReDim Preserve arrTemp(x) Else arrTemp(x) = arrTemp(x) & Char End If ElseIf Char = Chr(34) Then If inQuotes = False Then inQuotes = True Else x = x + 1 ReDim Preserve arrTemp(x) End If Else arrTemp(x) = arrTemp(x) & Char End If Next i Seperate = arrTemp End Function [/code] | December 29, 2002, 1:52 AM |
warz | Explain "as variant". Why'd you use it? What does it do? | December 29, 2002, 1:56 AM |
Noodlez | so that it returns as an array | December 29, 2002, 1:58 AM |
warz | Thanks, *atom* | December 29, 2002, 2:00 AM |
Atom | ;D | December 29, 2002, 11:34 AM |
warz | Actually that's rather usless to me | December 29, 2002, 1:28 PM |
dRAgoN | atleast he replyed huh ::) | December 29, 2002, 4:38 PM |
haZe | when you reply, why don't you post something we actually care about, warz? :-/ | December 29, 2002, 6:22 PM |
Yoni | You misspelled Separate :( Misspelled words in code are fatal, especially when working in programming teams. In a hypothetical situation a different programmer might try to call the nonexistent "Separate" function, get a compiler error, look at the code, see a "Seperate" function, scratch his/head several times, <repeat>. | December 29, 2002, 7:56 PM |
Grok | What is wrong with Split()? | December 29, 2002, 8:09 PM |
Eibro | [quote]You misspelled Separate :( Misspelled words in code are fatal, especially when working in programming teams. In a hypothetical situation a different programmer might try to call the nonexistent "Separate" function, get a compiler error, look at the code, see a "Seperate" function, scratch his/head several times, <repeat>.[/quote] Not to mention words like centre/center color/colour. Which I go trying to spell the >canadian< way :( | December 29, 2002, 10:02 PM |
Etheran | don't you mean center/centre color/colour ? | December 30, 2002, 9:35 PM |
warz | picky? more or less asking a stupid question... | December 30, 2002, 10:24 PM |
Grok | What is wrong with Split()? | December 30, 2002, 10:54 PM |
Spht | So what's wrong with Split()? | April 30, 2004, 3:55 AM |
iago | [quote] It splits by Spaces except when the spaces are inside quotes. It also ignores double spaces outside of quotes.[/quote] I don't think split can do that? | April 30, 2004, 11:55 AM |
Grok | You're right. | April 30, 2004, 1:48 PM |
LoRd | [quote author=iago link=board=31;threadid=716;start=15#msg57730 date=1083326120] [quote] It splits by Spaces except when the spaces are inside quotes. It also ignores double spaces outside of quotes.[/quote] I don't think split can do that? [/quote] Using a combination of Split() and InStr() could. | April 30, 2004, 3:02 PM |
Adron | [quote author=LoRd[nK] link=board=31;threadid=716;start=15#msg57747 date=1083337359] [quote author=iago link=board=31;threadid=716;start=15#msg57730 date=1083326120] [quote] It splits by Spaces except when the spaces are inside quotes. It also ignores double spaces outside of quotes.[/quote] I don't think split can do that? [/quote] Using a combination of Split() and InStr() could. [/quote] Would split be very useful at all? Unless you mean to find a substring that doesn't contain any "" and then split that separately.. | April 30, 2004, 3:03 PM |
Grok | RegEx could work here. | April 30, 2004, 3:18 PM |