Split Text
Split Text
Split Text
Split Text
Split Text
Split Text Split Text Split Text Split Text Split Text Split Text Split Text Split Text
Split Text Split Text
Split Text
Go Back  Xtreme Visual Basic Talk > > > Split Text


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2015, 08:32 AM
ufukes ufukes is offline
Newcomer
 
Join Date: Jan 2010
Posts: 1
Default Split Text


Hello, I know very little English sorry I would like to split the text as shown in the image.

0.0.0(14655158)vbcrlf
0.8.0(15*min)vbcrlf
0.9.1(17:29:17)vbcrlf
0.9.2(15-05-13)vbcrlf
0.9.5(3)vbcrlf
1.8.0(00000.000*kWh)vbcrlf
1.8.1(00000.000*kWh)vbcrlf
1.8.2(00000.000*kWh)vbcrlf
1.8.3(00000.000*kWh)vbcrlf
1.8.4(00000.000*kWh)vbcrlf
1.6.0(000.000*kW)(00-00-00,00:00)vbcrlf
96.1.3(14-11-04)vbcrlf
96.2.2(14-11-04,06:16)vbcrlf
96.2.5(14-11-04)vbcrlf
96.6.1(1)vbcrlf
96.50(0600170022009999999999999999)vbcrlf
96.51(0600170022009999999999999999)vbcrlf
96.52(0600170022009999999999999999)vbcrlf
96.60(31230000)vbcrlf
96.61(31230000)vbcrlf
96.62(31230000)vbcrlf
96.70(00-00-00,00:00)vbcrlf
96.71(00-00-00,00:00)(00)vbcrlf
96.71*01(00-00-00,00:00)(00)vbcrlf
96.71*02(00-00-00,00:00)(00)vbcrlf
Attached Images
File Type: png reg.png (31.1 KB, 6 views)
Reply With Quote
  #2  
Old 05-14-2015, 02:00 AM
Flyguy's Avatar
FlyguySplit Text Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,155
Default

If you are using Visual Basic 5 or 6 then look up the Split method in the help.
Reply With Quote
  #3  
Old 05-16-2015, 02:13 PM
ElderKnightSplit Text ElderKnight is offline
Senior Contributor

Forum Leader
 
Join Date: Oct 2003
Location: Central Florida
Posts: 1,275
Default

Actually, VB5 doesn't have Split() or Join().
You can write your own comparable functions easily enough though.

Splitting on the parentheses should help. I don't where you get that text from (in the attachment), though.
__________________
-- D.J.

I do not endorse any items advertised within this frame, and regret that the viewer is subjected to such.
Reply With Quote
  #4  
Old 05-17-2015, 03:08 AM
fafalone fafalone is offline
Freshman
 
Join Date: May 2010
Posts: 37
Default

I used to use this function that includes support to split by ( ) et al, and support for multiple delimiters, option to retain parenthetical-type delimiters, and even an array that records the position of each item (it's part of an obscenely complex renaming program).

Code:
Public Function SplitEx(sz As String, _
                        dlms As Variant, _
                        Optional lLimit As Long = 0, _
                        Optional comp As VbCompareMethod = vbBinaryCompare, _
                        Optional bTruncateLimit As Boolean = False, _
                        Optional bRParen As Boolean = False, _
                        Optional bRBrack1 As Boolean = False, _
                        Optional bRBrack2 As Boolean = False, _
                        Optional bPosOut As Boolean = False, _
                        Optional vPos As Variant _
                                                                            ) As Variant
'Splits a string with an array of delimiters
'Also allows an option to split by pairs () [] {}
'with a further option to retain those characters
'when splitting

comp = cmDelim


Dim i As Long, j As Long, k As Long, c As Long, ST As Long, dl As Long
Dim szPart As String
Dim ar As Variant
Dim szDelims As String
Dim bParen As Boolean
Dim bBrack1 As Boolean
Dim bBrack2 As Boolean
ReDim vPos(0)

For i = LBound(dlms) To UBound(dlms)
    If (dlms(i) = "(") Or (dlms(i) = "()") Then
        bParen = True
        dlms(i) = ""
    End If
    If (dlms(i) = "[") Or (dlms(i) = "[]") Then
        bBrack1 = True
        dlms(i) = ""
    End If
    If (dlms(i) = "{") Or (dlms(i) = "{}") Then
        bBrack2 = True
        dlms(i) = ""
    End If
Next i

'szDelims = Join(dlms)

szPart = ""
ReDim ar(0)
c = 0

For i = 1 To Len(sz)
If (lLimit > 0) And (UBound(ar) = lLimit - 1) And (i < Len(sz)) And (bTruncateLimit = False) Then
    ar(c) = Mid(sz, i)
    Exit For
ElseIf (lLimit > 0) And (UBound(ar) = lLimit) And (i < Len(sz)) And (bTruncateLimit = True) Then
    Exit For
End If
    If bParen And (Mid(sz, i, 1) = "(") Then
        If szPart <> "" Then
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If

            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
        End If
        j = InStr(i + 1, sz, ")")
        If j - (i + 1) > 0 Then
            For k = i + 1 To j - 1
                szPart = szPart & Mid(sz, k, 1)
            Next k
            If bRParen Then
                szPart = "(" & szPart & ")"
            End If
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If
            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
            i = j
            GoTo nxt
        End If
    End If
    If bBrack1 And (Mid(sz, i, 1) = "[") Then
        If szPart <> "" Then
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If

            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
        End If
        j = InStr(i + 1, sz, "]")
        If j - (i + 1) > 0 Then
            For k = i + 1 To j - 1
                szPart = szPart & Mid(sz, k, 1)
            Next k
            If bRBrack1 Then
                szPart = "[" & szPart & "]"
            End If
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If

            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
            i = j
            GoTo nxt
        End If
    End If
    If bBrack2 And (Mid(sz, i, 1) = "{") Then
        If szPart <> "" Then
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If

            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
        End If
        j = InStr(i + 1, sz, "}")
        If j - (i + 1) > 0 Then
            For k = i + 1 To j - 1
                szPart = szPart & Mid(sz, k, 1)
            Next k
            If bRBrack2 Then
                szPart = "{" & szPart & "}"
            End If
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If

            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
            i = j
            GoTo nxt
        End If
    End If
'    If (InStr(1, szDelims, Mid(sz, i, 1), comp)) And ((szPart <> "") Or (UBound(ar) > 0)) Then
'        If szPart <> "" Then
'        ar(c) = szPart
'        c = c + 1
'        szPart = ""
'        ReDim Preserve ar(c)
'        End If
    dl = check_dlm(Mid(sz, i), dlms, comp)
    If dl > -1 Then
        If szPart <> "" Then
            ar(c) = szPart
            If bPosOut Then
                vPos(c) = i - Len(szPart)
                ReDim Preserve vPos(c + 1)
            End If

            c = c + 1
            szPart = ""
            ReDim Preserve ar(c)
            i = i + (dl - 1) 'advance position by length of matched delimiter (minus the one Next adds)
        End If
    Else
        szPart = szPart & Mid(sz, i, 1)
    End If
nxt:
Next i

If szPart <> "" Then
    ar(UBound(ar)) = szPart
    If bPosOut Then
        vPos(UBound(vPos)) = i - Len(szPart)
    End If

Else
    If CStr(ar(UBound(ar))) = "" Then
        ReDim Preserve ar(UBound(ar) - 1)
    End If
    If bPosOut Then
        If CStr(vPos(UBound(vPos))) = "" Then
            ReDim Preserve vPos(UBound(vPos) - 1)
        End If
    End If
End If


SplitEx = ar

End Function
Public Function check_dlm(szMid As String, d As Variant, cm As VbCompareMethod) As Long
'given a string starting at the point of interest, checks through an array
'of variable length delimiters and determines if the first characters
'match any of the delimiters.
'If it does, the length of the applicable delimiter is returned, otherwise
'the return is -1
Dim i As Long, j As Long
Dim tmpD As String

For i = LBound(d) To UBound(d)
    tmpD = d(i)
    If StrComp(Left(szMid, Len(tmpD)), tmpD, cm) = 0 Then
        check_dlm = Len(tmpD)
        Exit Function
    End If
Next i
check_dlm = -1
End Function
Not efficient or fast, but flexible.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Split Text
Split Text
Split Text Split Text
Split Text
Split Text
Split Text Split Text Split Text Split Text Split Text Split Text Split Text
Split Text
Split Text
 
Split Text
Split Text
 
-->