Sort String 1 (from end): Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:Afrow UK|Afrow UK]] ([[{{ns:3}}:Afrow UK|talk]], [[{{ns:-1}}:Contributions/Afrow UK|contrib]])</small>
|}
<br style="clear:both;">
== Description ==
== Description ==
This script will output all after x spaces, where x is the space count from the end of the input string.
This script will output all after x spaces, where x is the space count from the end of the input string.
Line 46: Line 50:


-Stu
-Stu
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 03:04, 30 April 2005

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