Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays reverse order, splitting one line of strings
#1
Hello everyone,

I want to achieve the same effect in QM as powershell code, 
Included: Arrays reverse order, and splitting one line of strings

Code Description:
Split the last line of string from where the first # character, 
All Lines, in reverse order, then merged together with spaces between, Final after the #character is placed at the end(keep #)

The end result:
I'm in the third line I'm the second line I'm in the first line #foo #ball

Powershell execution is slow, using QM should be faster, 

Thanks for any advice and help
david


Macro Macro7
Code:
Copy      Help
out
_s = 
;I'm in the first line
;I'm the second line
;I'm in the third line #foo #ball

;todo: split The third line of the string, separator # keep #

ARRAY(str) a
a=_s
a.sort(1) ;;Reverse order does not take effect
str d

for _i 0 a.len
,d.formata("%s " a[_i].trim)
out d


Powershell code:
Code:
Copy      Help
 
$s = @'
I'm in the first line
I'm the second line
I'm in the third line #foo #ball
'@

$arr = $s -split '\n'
$x, $y = $arr[-1] -split '(?=#)', 2
$arr = @(
  if ($null -ne $y) { $y }
  $arr | Select-Object -SkipLast 1
  $x.trim()
)
[array]::Reverse($arr)
$arr -join ' '


Messages In This Thread
Arrays reverse order, splitting one line of strings - by Davider - 07-21-2022, 11:42 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)