Bug? [SOLVED] regex.split failure

Discussion in 'iOS Bugs & Wishlist' started by sorex, Jan 12, 2015.

  1. sorex

    sorex Expert Licensed User

    Hello,

    for some reason this fails in B4i while it worked fine in B4A.

    Code:
    data=Regex.Split("",num)
    num is for example "0200"

    it works fine when using 0,2,0,0 & "," as seperator tho but "" should work aswell.


    the log gives

    Code:
    Error occurred on line: 196 (gameclass)
    Error Domain=NSCocoaErrorDomain Code=
    2048 "The operation couldn’t be completed. (Cocoa error 2048.)" UserInfo=0x145f1b60 {NSInvalidValue=}
    Stack Trace: (
      CoreFoundation  <redacted> + 154
      libobjc.A.dylib  objc_exception_throw + 38
      CoreFoundation  <redacted> + 0
      CLAUStrophoba  +[B4IRegex getPattern::] + 536
      CLAUStrophoba  -[B4IRegex Split2:::] + 126
      CLAUStrophoba  -[B4IRegex Split::] + 80
      CoreFoundation  <redacted> + 68
      CoreFoundation  <redacted> + 282
      CLAUStrophoba  +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1928
      CLAUStrophoba  -[B4IShell runMethod:] + 496
    CLAUStrophoba  -[B4IShell raiseEventImpl:method:args::] + 1846
    CLAUStrophoba  -[B4IShellBI raiseEvent:event:params:] + 1316
    CLAUStrophoba  __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
    libdispatch.dylib  <redacted> + 10
    libdispatch.dylib  <redacted> + 22
    libdispatch.dylib  <redacted> + 254
    CoreFoundation  <redacted> + 8
    CoreFoundation  <redacted> + 1300
    CoreFoundation  CFRunLoopRunSpecific + 522
    CoreFoundation  CFRunLoopRunInMode + 106
    GraphicsServices  GSEventRunModal + 138
    UIKit  UIApplicationMain + 1136
    CLAUStrophoba  main + 116
    libdyld.dylib  <redacted> + 2
    )
     
  2. LucaMs

    LucaMs Expert Licensed User

    "" without a space?

    If so, according to "the logic" it should return an array with a single element, "0200"

    (I have not B4I and not tried with B4A)


    [without a space it is like passing a null parameter, I think].
     
  3. sorex

    sorex Expert Licensed User

    no, "" means split on every character.
     
  4. sorex

    sorex Expert Licensed User

    I could use charat but I apply a lot of math with those values and charat doesn't seem to cast right from string to my int and won't compile so I need to change a lot more than with my regex.split("",var) solution.
     
  5. LucaMs

    LucaMs Expert Licensed User


    More precisely, it is what you would like it meant, but I fear that it is not so.
     
  6. sorex

    sorex Expert Licensed User

    I used this trick in several languages so it's not my own invention ;)

    also... there is a difference between undefined, null and ""
     
  7. LucaMs

    LucaMs Expert Licensed User

    I tried using B4A and the empty string works as you want, but the array must be of type string.

    (B4A code, of course)
    Code:
    Dim Text As String = "0200"
    Dim A() As String = Regex.Split("", Text)
    For i = 0 To A.Length - 1
        
    Log(i & " " & A(i))
    Next
      
    Dim B(a.Length) As Byte
    For i = 0 To A.Length - 1
        B(i) = A(i)
    Next
    ?
     
  8. sorex

    sorex Expert Licensed User

    flash actionscript: Splits a String object into substrings by breaking it wherever the specified delimiter parameter occurs and returns the substrings in an array. If you use an empty string ("") as a delimiter, each character in the string is placed as an element in the array.


    javascript:
    The split() method is used to split a string into an array of substrings, and returns the new array.

    Tip: If an empty string ("") is used as the separator, the string is split between each character.


    and so on
     
  9. sorex

    sorex Expert Licensed User

    right, it works fine in B4A as I said in my initial post.

    it might be an IOS limitation.
     
  10. LucaMs

    LucaMs Expert Licensed User

    I don't know using b4i, but "data" should be an array of strings, using b4a; perhaps even with b4i?
     
  11. sorex

    sorex Expert Licensed User

    bummer... :(


    The separator string can't be blank. If you need to separate a string into its individual characters, just loop through the length of the string and convert each char into a new string:

    NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[myString length]];
    for (int i=0; i < [myString length]; i++) {
    NSString *ichar = [NSString stringWithFormat:mad:"%c", [myString characterAtIndex:i]];
    [characters addObject:ichar];
    }
     
  12. sorex

    sorex Expert Licensed User

    and like I said I need other extra code to get the casting right.

    it can be done like this unless Erel has some more decent/elegant method

    Code:
    tmpstring=cartypedata.charat(0'grab value
    xoffset=tmpstring 'cast to int as immediate cast with charat fails (won't compile)
     
  13. LucaMs

    LucaMs Expert Licensed User

    Fortunately I do not use iOS :D, so I can not help you, sorry.
     
  14. sorex

    sorex Expert Licensed User

    no problem, Luca.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    The correct way to iterate over the string characters:
    Code:
    Dim s As String = "SdfsdfsdF"
    For i = 0 To s.Length - 1
       
    Dim c As Char = s.CharAt(i)
       
    Log(c)
    Next
     
  16. sorex

    sorex Expert Licensed User

    Yes, that's how I solved it last night.

    You can forget/drop this issue. :)
     
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