Sort String 1 (from end): Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
m (Adding new author and category links.)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|Afrow UK}}
|<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 50: Line 48:


-Stu
-Stu
[[Category:String Functions]]

Latest revision as of 13:52, 24 June 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