Jump to content

StringLeft multiline


Recommended Posts

I come from here: https://www.autoitscript.com/forum/topic/36064-string-delete-after-character/

Im trying to copy some multiline text like this from clipboard:

text text tex text            123x 2x34 345
text text tex text            123 23x4 3x45
text text tex text            123 2x34 345

So I need to remove any character after "spaces" in every line and putit into clipboard with this format:

text text tex text          
text text tex text          
text text tex text     
      

Im using StringLeft and I it's alright for one line. Is possible to make it multiline?


 

$String = ClipGet()

$OutPut = StringLeft($String, StringInStr($String, '     ') + 0)

ClipPut ($OutPut)

 

Thank you!

Link to comment
Share on other sites

Opt("ExpandVarStrings", 1)

$in = "text text tex text            123x 2x34 345@CRLF@" & _
"text text tex text            123 23x4 3x45@CRLF@" & _
"text text tex text            123 2x34 345"

$in = StringSplit(StringStripCR($in), @LF)
$out = ""
For $i = 1 To $in[0]
   $out &= StringLeft($in[$i], StringInStr($in[$i], '     ') + 0) & @LF
Next

ConsoleWrite($out)

I would use StringSplit.

Link to comment
Share on other sites

and the (simple) regex which fits nice... 

$txt = "text text tex text            123x 2x34 345" & @crlf & _ 
    "text text tex text            123 23x4 3x45" & @crlf & _ 
    "text text tex text            123 2x34 345"

$res = StringRegExpReplace($txt, '(?m)^(.*?)\h{2,}.*', "$1") 
Msgbox(0,"", $res)

:)

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