using regEx

Discussion in 'Questions (Windows Mobile)' started by Byak@, Jun 4, 2009.

  1. Byak@

    Byak@ Active Member Licensed User

    i have string
    Code:
    test test(test[COLOR=Red],[/COLOR]test[COLOR=Red],[/COLOR]test()[COLOR=Red],[/COLOR]")"[COLOR=Red],[/COLOR]"("[COLOR=Red],[/COLOR]"test,"[COLOR=Red],[/COLOR]",test") test
    i was replace ',' to '&"*"&'
    result must be
    Code:
    test test(test[COLOR=Red]&"*"&[/COLOR]test[COLOR=Red]&"*"&[/COLOR]test()[COLOR=Red]&"*"&[/COLOR]")"[COLOR=Red]&"*"&[/COLOR]"("[COLOR=Red]&"*"&[/COLOR]"test,"[COLOR=Red]&"*"&[/COLOR]",test") test
    i'm try to do it with basic's string methods but can't.for first i want select test,test,test(),")","(","test,",",test"

    Code:
    'replace ',' as '&"*"&'
    newcode="test test(test,test,test(),")","(","test,",",test") test"
    lastc=
    "test("

    i=StrIndexOf(newcode,lastc,i)
    i=i+StrLength(lastc)
    'find ')'
    i1=StrIndexOf(newcode,")",i)
    'check for '"...)..."'
    i2=StrIndexOf(newcode,Chr(34),i)
    i3=StrIndexOf(newcode,
    Chr(34),i2+1)
    s=
    0
    If i1>i2 AND i1<i3 Then s=1
    Do While s=1
    s=
    0
    i1=StrIndexOf(newcode,
    ")",i3)
    i2=StrIndexOf(newcode,
    Chr(34),i3+1)
    If i1<>-1 AND i2<>-1 Then
    i3=StrIndexOf(newcode,
    Chr(34),i2+1)
    If i1>i2 AND i1<i3 Then s=1
    End If
    Loop
    'find '('
    i2=StrIndexOf(newcode,"(",i)
    'check for '"...(..."'
    i3=StrIndexOf(newcode,Chr(34),i)
    i4=StrIndexOf(newcode,
    Chr(34),i3+1)
    s=
    0
    If i2>i3 AND i2<i4 Then s=1
    Do While s=1
    s=
    0
    i2=StrIndexOf(newcode,
    "(",i4)
    i3=StrIndexOf(newcode,
    Chr(34),i4+1)
    If i2<>-1 AND i3<>-1 Then
    i4=StrIndexOf(newcode,
    Chr(34),i3+1)
    If i2>i3 AND i2<i4 Then s=1
    End If
    Loop
    'find index of last ')'
    If i2<>-1 Then
    Do While i2<i1
    i3=i1
    i1=StrIndexOf(newcode,
    ")",i3+1)
    i2=StrIndexOf(newcode,
    "(",i3+1)
    If i2=-1 Then i2=i1+1
    Loop
    End If
    Msgbox(SubString(newcode,i,i1-i))
    i'm start reading manuals for RegEx but :BangHead:
    help me please!
     
    Last edited: Jun 4, 2009
  2. Erel

    Erel Administrator Staff Member Licensed User

    Here:
    Code:
    Sub App_Start
        q = 
    Chr(34)
        
    'str = "test test(test,test,test(),")","(","test,",",test") test"
        str = "test test(test,test,test(),"&q&")"&q&","&q&"("&q&","&q&"test,"&q&","&q&",test"&q&") test"
        inQuote = 
    False
        i = 
    0
        
    Do While i < StrLength(str)
            c = StrAt(str, i)
            
    If c = Chr(34Then 
                inQuote = 
    Not(inQuote)
            
    Else If c = "," AND inQuote = False Then
                str = StrRemove(str, i, 
    1)
                str = StrInsert(str, i, 
    "&"&q&"*"&q&"&")
                i = i + 
    3
            
    End If
            i = i + 
    1
        
    Loop
        
    Msgbox(str)
    End Sub
     
  3. Byak@

    Byak@ Active Member Licensed User

    Thanks Erel but i'm already do it :-[
    i want foud faster method...
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice