Jump to content

StringLeft/Right -> unwanted chars in last string [SOLVED]


Rex
 Share

Recommended Posts

Hi

I'm using this code to split inputs into groups of 56 chars

$String = "232121-232323-232323-232323-232323-232323-784512-895623-235689-784512-134679-976431-852963-362514-784596-aswert-klionm-tyghbn-yhntgb-pæøåoi-ujmtgb-edfrtg-qaswed-vfryhn-uytrfg-oiuytr-åååååå"
$len = StringLen($String)
if $len > "224" Then
    $String4 = StringRight(StringRight(StringRight(StringLeft($String, 224), 168),112),56)
    $String3 = StringRight(StringRight(StringLeft($String, 168), 112),56)
    $String2 = StringRight(StringLeft($String, 112), 56)
    $String1 = StringLeft($String, 56)
ConsoleWrite("Strengens Længde = " & $len & @CRLF & "Strengen der bliver splittet = " & $String & @CRLF & "Streng 1 = " & $String1 & @CRLF & _
"streng 2 = " & $String2 & @CRLF & "Streng 3 = " & $String3 & @CRLF & "Streng 4 = " & $String4 & @CRLF)
ElseIf $len > "168" Then
    $String4 = StringRight(StringRight(StringRight(StringLeft($String, 224), 168),112),56)
    $String3 = StringRight(StringRight(StringLeft($String, 168), 112),56)
    $String2 = StringRight(StringLeft($String, 112), 56)
    $String1 = StringLeft($String, 56)
    ConsoleWrite("Strengens Længde = " & $len & @CRLF & "Strengen der bliver splittet = " & $String & @CRLF & "Streng 1 = " & $String1 & @CRLF & _
"streng 2 = " & $String2 & @CRLF & "Streng 3 = " & $String3 & @CRLF & "Streng 4 = " & $String4 & @CRLF)

ElseIf $len > "112" Then
$String3 = StringRight(StringRight(StringLeft($String, 168), 112),56)
    $String2 = StringRight(StringLeft($String, 112), 56)
    $String1 = StringLeft($String, 56)
    ConsoleWrite("Strengens Længde = " & $len & @CRLF & "Strengen der bliver splittet = " & $String & @CRLF & "Streng 1 = " & $String1 & @CRLF & _
"streng 2 = " & $String2 & @CRLF & "Streng 3 = " & $String3 & @CRLF)
ElseIf $len > "56" Then
    $TrimR = $len - 56
    $String2 = StringRight($String, $TrimR)
    $String1 = StringLeft($String, 56)
    ConsoleWrite("Strengens Længde = " & $len & @CRLF & "Strengen der bliver splittet = " & $String & @CRLF & "Streng 1 = " & $String1 & @CRLF & _
"streng 2 = " & $String2 & @CRLF)
EndIf

But for some reason i get "doubles" when i have > 112 chars but i can't see why

can any of u throw me a bone, to what's wrong with my code :D

Cheers

/Rex

Edited by Rex
Link to comment
Share on other sites

Does this function help you?

;~ Beispieltext von http://de.wikipedia.org/wiki/AutoIt
;$String = "Die Skripteermöglichenz.B. das Ausführen von Programmen, das Simulieren von Tastaturanschlägen bzw. Mausklicks. Es können einfache Textfunktionen der Zwischenablage oder auch Windowsfunktionen (wie z. B. minimieren, verstecken, Warten auf/Aktivieren von Fenstern) aufgerufen werden. Seit Version 3 können zudem graphische Benutzeroberflächen mit zahlreichen Controls entworfen werden. Soll es um Registrymanipulationen oder komplexere Schleifen gehen, ist AutoIt 3 inzwischen mit seiner verbesserten Syntax deutlich einfacher zu handhaben als frühere Versionen. Es ist möglich, AutoIt mit anderen Scriptsprachen wie WSH oder Kixtart zu kombinieren (AutoItX)."
$String = "232121-232323-232323-232323-232323-232323-784512-895623-235689-784512-134679-976431-852963-362514-784596-aswert-klionm-tyghbn-yhntgb-pæøåoi-ujmtgb-edfrtg-qaswed-vfryhn-uytrfg-oiuytr-åååååå"

MsgBox(0, "Original", $String) ; Original-Text
MsgBox(0, "Softbreak", _StringInsertLF($String, 56)) ; Softbreak nach 50 Zeichen
MsgBox(0, "Hardbreak", _StringInsertLF($String, 56, 1)) ; Hardbreak nach 50 Zeichen

;===============================================================================
;
; Description:  Fügt @LF in Strings ein
; Parameter(s):     $strString = String der bearbeitet werden soll
;   $nCount     = Anzahl der Zeichen bevor @LF eingefügt werden soll
;   (optional) $cBreaking = 0 (default) -> Softbreak (an Wortgrenze)
;   1   -> Hardbreak
;   ist kein Leerzeichen im String enthalten wird hart
;   umgebrochen
; Requirement(s): keine
; Return Value(s): String mit @LF
; Author(s):    bernd670
;
;===============================================================================
Func _StringInsertLF($strString, $nCount, $cBreaking = 0)
    Local $strRetString = "", $nPos
    Do
        ; If Stringlen($strString) > $nCount Then
        $nPos = StringInStr(StringLeft($strString, $nCount + 1), " ", 0, -1)
        If ($nPos And $cBreaking = 0) Then
            $strRetString &= StringLeft($strString, $nPos - 1) & @LF
            $strString = StringMid($strString, $nPos + 1)
        Else
            $strRetString &= StringLeft($strString, $nCount) & @LF
            $strString = StringMid($strString, $nCount + 1)
        EndIf
        ; EndIf
    Until StringLen($strString) < $nCount
    $strRetString &= $strString
    Return $strRetString
EndFunc ;==>_StringInsertLF

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Rex,

I would split the string like this:

$sString = "232121-232323-232323-232323-232323-232323-784512-895623-235689-784512-134679-976431-852963-362514-784596-aswert-klionm-tyghbn-yhntgb-pæøåoi-ujmtgb-edfrtg-qaswed-vfryhn-uytrfg-oiuytr-åååååå"

$nSubStrings = (StringLen($sString) + 1) / 63

ConsoleWrite("Strengens Længde = " & StringLen($sString) & @CRLF & "Strengen der bliver splittet = " & $sString & @CRLF)

$iSubstrings = Ceiling($nSubStrings)

Global $aCutStrings[$iSubstrings]

For $i = 0 To $iSubstrings - 1
    $aCutStrings[$i] = StringMid($sString, (63 * $i) + 1, 62)
    ConsoleWrite("Streng " & $i + 1 & " = " & $aCutStrings[$i] & @CRLF)
Next

I hope this helps! :D

M23

Edit: Just remembered Ceiling!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'm using this code to split inputs into groups of 56 chars

But for some reason i get "doubles" when i have > 112 chars but i can't see why

You're making this unduly complicated.

Try this:

#include <Array.au3>
Local Const $limit = 56
Local $String = "232121-232323-232323-232323-232323-232323-784512-895623-235689-784512-134679-976431-852963-362514-784596-aswert-klionm-tyghbn-yhntgb-pæøåoi-ujmtgb-edfrtg-qaswed-vfryhn-uytrfg-oiuytr-åååååå"
Local $len = StringLen($String)
Local $nbStr = Floor(($len + $limit - 1) / $limit)
Local $aStrings[$nbStr]
For $i = 0 To $nbStr - 1
    $aStrings[$i] = StringLeft($String, $limit)
    $String = StringTrimLeft($String, $limit)
Next
_ArrayDisplay($aStrings)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Wow

I just posted this :D

And already got 3 responses, Cool :huggles:

I'll look at em and post back (need to find out how to put it into this (http://www.autoitscript.com/forum/index.php?showtopic=108385)

Cheers

/Rex

Link to comment
Share on other sites

  • 7 months later...

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...