Sort String 1 (from end)

From NSIS Wiki
Jump to navigationJump to search
Author: Afrow UK (talk, contrib)


Description

This script will output all after x spaces, where x is the space count from the end of the input string.

Usage

Push "I am Afrow UK"
Push 2
 Call SimpStrSort
Pop $R0

$R0 will now be "Afrow UK", since "Afrow UK" is after the 2nd space from the end of the string.

The Function

Function SimpStrSort
  Exch $4 ; count to get part
  Exch
  Exch $0 ; input string
  Push $1
  Push $2
  Push $3
  StrCpy $1 0
  StrCpy $3 1
  loop:
    IntOp $1 $1 - 1
    StrCpy $2 $0 1 $1
    StrCmp $2 "" exit2
    StrCmp $2 " " next ; replace " " with whatever you like
    Goto loop
  next:
    StrCmp $3 $4 exit
    IntOp $3 $3 + 1
  Goto loop
  exit2:
    IntOp $1 $1 - 1
  exit:
    IntOp $1 $1 + 1
    StrCpy $0 $0 "" $1
    Pop $3
    Pop $2
    Pop $1
    Exch $0 ; output string
FunctionEnd

-Stu