Sign in to follow this  
Followers 0
Codemike

How can do newline StringSplit?

11 posts in this topic

If I do StringSplit(clipget(), " ") how I can do that line last word and new line first word don't merge? (I can see that if I use _ArrayDisplay() ).

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try something like this:

#include <Array.au3>
$t = ClipGet()
$aT = StringSplit(StringReplace($t, Chr(13), ""), Chr(10), 2)
Dim $aFinal[UBound($aT)][100000]
$ub = 0
For $h = 0 To UBound($aT) - 1
    $array = StringSplit($aT[$h], "", 2)
    If $ub < UBound($array) Then $ub = UBound($array)
    For $i = 0 To UBound($array) - 1
        $aFinal[$h][$i] = $array[$i]
    Next
Next
ReDim $aFinal[UBound($aT)][$ub]
_ArrayDisplay($aFinal)

This is just a simple example and has enough room for improvement.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Try something like this:

#include <Array.au3>
$t = ClipGet()
$aT = StringSplit(StringReplace($t, Chr(13), ""), Chr(10), 2)
Dim $aFinal[UBound($aT)][100000]
$ub = 0
For $h = 0 To UBound($aT) - 1
    $array = StringSplit($aT[$h], "", 2)
    If $ub < UBound($array) Then $ub = UBound($array)
    For $i = 0 To UBound($array) - 1
        $aFinal[$h][$i] = $array[$i]
    Next
Next
ReDim $aFinal[UBound($aT)][$ub]
_ArrayDisplay($aFinal)

This is just a simple example and has enough room for improvement.

Br,

UEZ

Thanks, but I'm a beginner in the programming and I have tryed much think how I can continue that I get words that original form without words merge (and can use example $word[x] call)?

Share this post


Link to post
Share on other sites

Do you want to split in words instead of letters?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Do you want to split in words instead of letters?

Br,

UEZ

Words if it is possible some way? (I have done some program when I noticed that line last word and new line first word merge in StringSplit and looking hard solving to problem.)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If you replace line 7 with

$array = StringSplit($aT[$h], " ", 2)

it will split at space.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

If you replace line 7 with

$array = StringSplit($aT[$h], " ", 2)

it will split at space.

Br,

UEZ

Thanks very much that you try to help me. But this your example unfortunately don't work. Maybe problem is very difficult because anyone else don't help?

Share this post


Link to post
Share on other sites

This is one of those times where you've attempted to follow the forum rules, and the translation is getting lost I think.

I'd suggest you posting your question in your native language now. Maybe someone that speaks it will understand.


[center]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.[/center]

Share this post


Link to post
Share on other sites

Codemike,

I believe the problem (and solution) is very simple. You are splitting the text on the spaces and the @CRLF at the end of each line is not splitting.

Just use StringReplace to change the @CRLF to spaces and the StringSplit works as you wish: ;)

#include <Array.au3>

$sText = "This is line 1" & @CRLF & _
         "This is line 2" & @CRLF & _
         "This is line 3" & @CRLF & _
         "This is line 4"

$aStringSplit = StringSplit(StringReplace($sText, @CRLF, " "), " ")

_ArrayDisplay($aStringSplit)

Is that what you wanted? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

The way I'd do it Melba is use StringStripCR and then use the fact that StringSplit accepts multiple splits... You might also want to treat double spaces as being one:

#include <Array.au3>

$sText = "This is line 1" & @CRLF & _
         "This is line 2" & @CRLF & _
         "This is line 3" & @CRLF & _
         "This is line 4"

$aStringSplit = StringSplit(StringStripWS(StringStripCR($sText), 4), " " & @LF)

_ArrayDisplay($aStringSplit)

Just a few more things to think about :)

Mat

Share this post


Link to post
Share on other sites

The way I'd do it Melba is use StringStripCR and then use the fact that StringSplit accepts multiple splits... You might also want to treat double spaces as being one:

#include <Array.au3>

$sText = "This is line 1" & @CRLF & _
         "This is line 2" & @CRLF & _
         "This is line 3" & @CRLF & _
         "This is line 4"

$aStringSplit = StringSplit(StringStripWS(StringStripCR($sText), 4), " " & @LF)

_ArrayDisplay($aStringSplit)

Just a few more things to think about :)

Mat

Thanks very much evryone who help me. Yes now it works what I need.

#include <Array.au3>

clipget()

$sText = clipget()

$aStringSplit = StringSplit(StringReplace($sText, @CRLF, " "), " ")

_ArrayDisplay($aStringSplit)

Share this post


Link to post
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
Sign in to follow this  
Followers 0