Jump to content

StringSplit only returning a few characters


Recommended Posts

I'm working on a type of EBook reader (I call SBoox, pronounced Ess Books) and I'm having a wee bit of trouble with the "page" system. It is a human readable format with the extension "sbk", and it's basically text separated by a delimiter (In this case: {newpage})

Here is the reader so far:

#include <GUIConstants.au3>
Global $pagecount, $temppage
$Form1 = GUICreate("", 493, 574, 193, 115)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 489, 513)
$hMenu = GUICtrlCreateMenu("SBoox")
$hOpen = GUICtrlCreateMenuItem("Open SBook", $hMenu)
$hNext = GUICtrlCreateButton("Next Page", 72, 528, 65, 17, 0)
$hPrev = GUICtrlCreateButton("Previous Page", 344, 528, 73, 17, 0)
$Input1 = GUICtrlCreateInput("", 216, 528, 49, 21, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MAXIMIZE
            MsgBox(0, "Test", "Lolz")
        Case $hOpen
            $temppage = GUICtrlRead($Edit1)
            $fOpen = FileOpenDialog("Open SBook", "f:\Scripts\", "SBoox Books (*.sbk)")
            If @error Then
                MsgBox(0x10, "Error", "Error opening file")
                GUICtrlSetData($Edit1, $temppage)
                ExitLoop
            EndIf
            $szPages = _LoadSBook($fOpen, "{newpage}")
            GUICtrlSetData($Edit1, $szPages[1])
            $pagecount = 1
        Case $hNext
            If IsArray($szPages) Then
                If $pagecount < $szPages[0] Then
                    GUICtrlSetData($Edit1, $szPages[$pagecount + 1])
                    $pagecount = $pagecount + 1
                EndIf
            EndIf
        Case Else
            Sleep(20)
    EndSwitch
WEnd

Func _LoadSBook($sPath, $sNewPageDilemeter)
    Local $fData, $split
    If Not FileExists($sPath) Then
        Return -1
    EndIf
    $fData = FileRead($sPath)
    $split = StringSplit($fData, $sNewPageDilemeter)
    If Not IsArray($split) Then
        Return -1
    EndIf
    Return $split
EndFunc   ;==>_LoadSBook

And this is a test SBook:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean pellentesque. Sed mauris nisl, consequat eget, scelerisque vitae, varius a, tellus. Duis sodales ultrices quam. Praesent lacinia leo a lorem. Duis facilisis ante ac sapien luctus gravida. Sed faucibus lobortis lacus. Pellentesque nisi leo, pharetra quis, facilisis at, interdum at, tellus. Morbi tincidunt, dui ac sollicitudin egestas, odio elit blandit est, eu scelerisque nulla neque gravida tellus. Integer quam. Suspendisse auctor elit auctor odio. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque massa. Mauris et quam. Nulla sed ligula vel ipsum commodo dapibus. Ut aliquam feugiat massa. Nullam sit amet neque. Pellentesque scelerisque. Duis mi est, fermentum vitae, suscipit nec, dignissim eget, quam.{newpage}
Pellentesque suscipit laoreet massa. Donec consectetuer diam eu arcu. Nulla at nisl. Pellentesque ac ligula. Pellentesque vel nulla a quam tempus gravida. Vivamus quam enim, tempus eu, posuere a, condimentum varius, sapien. Proin massa. Mauris nec erat. Etiam semper lectus vel diam suscipit feugiat. Ut adipiscing. Cras vestibulum gravida nisl. Suspendisse elementum pretium diam. Sed sapien tellus, lacinia eget, egestas et, vestibulum in, quam. Mauris dignissim nunc eget sem gravida feugiat. Morbi et massa. Morbi ornare molestie nibh. Aenean sit amet turpis at quam laoreet elementum. Vivamus pharetra convallis turpis. Nullam condimentum libero vestibulum enim. Sed et magna.{newpage}
Suspendisse ornare nonummy est. Cras placerat, erat ut scelerisque dignissim, est erat facilisis est, sit amet gravida pede nisi et sem. Fusce elit. Curabitur ultricies neque non lectus. Praesent varius auctor erat. Quisque a mi. Aliquam erat volutpat. Suspendisse sem. Aliquam fringilla, purus et bibendum commodo, lorem neque imperdiet magna, et tempus metus ante eu diam. Ut vestibulum sagittis ligula. Sed sit amet tortor eu arcu commodo iaculis. Morbi in mi eget sapien mattis volutpat. Nunc dictum bibendum turpis. Aenean orci ligula, vulputate sed, molestie vel, aliquet quis, ante. Curabitur pretium, lacus sed vestibulum pretium, tortor arcu imperdiet nisl, ut blandit mi enim quis sapien.{newpage}

^^Made with a Lorem Ipsum generator

If you save that as an sbk file, and run it with the above script, Each page is 2-5 characters long. And, when you press "Next Page", it skips a character before showing the next 3-5 characters. So each page is like:

Lo r...Psu... Do...oram... Etc

Does anyone know what's wrong?

Link to comment
Share on other sites

Read the help file under StringSplit() and check out the "flag" parameter:

StringSplit

--------------------------------------------------------------------------------

Splits up a string into substrings depending on the given delimiters.

StringSplit ( "string", "delimiters" [, flag ] )

Parameters

--------------------------------------------------------------------------------

string = The string to evaluate.

delimiters = One or more characters to use as delimiters (case sensitive).

flag [optional] = If flag is 0 (the default), then each character in the delimiter string will mark where to split the string. If flag is 1, then the entire delimiter string is needed to mark the split.

:)
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Oops :)

EDIT: To my defense, I couldn't get the helpfile running under Wine :)

Let us just forget this ever happened...

I'm sure you can get the internet running :party:http://www.autoitscript.com/autoit3/docs/

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...