Sort String 3 modified: 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 is the same as the [[Sort String 3]] script, but instead works from the start instead of the end of the input string.
This is the same as the [[Sort String 3]] script, but instead works from the start instead of the end of the input string.
Line 66: Line 70:


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

Revision as of 03:04, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

This is the same as the Sort String 3 script, but instead works from the start instead of the end of the input string.

Usage

Push "jajaja hello\muahah jajaj\lalala " ;input string
Push "\" ;centre character
Push " " ;right character
Push " " ;left character
 Call StrSortLR2
Pop $0

$0 = hello\muahah (not jajaj\lalala" in StrSortLR case)

The Function

Function StrSortLR2
Exch $0 ;left character
Exch
Exch $1 ;right character
Exch
Exch 2
Exch $2 ;centre character
Exch 2
Exch 3
Exch $3 ;input string
Exch 3
Push $4
Push $5
  StrLen $5 $3
loop1:
  IntOp $5 $5 - 1
  StrCpy $4 $3 1 -$5
  StrCmp $4 "" error
  StrCmp $4 $2 0 loop1
   IntOp $5 $5 - 1
 loop2:
   StrCpy $4 $3 1 -$5
   IntOp $5 $5 - 1
   StrCmp $4 "" loop3
   StrCmp $4 $1 0 loop2
    IntOp $5 $5 + 1
    StrCpy $3 $3 -$5
    StrLen $5 $3
  loop3:
    IntOp $5 $5 - 1
    StrCpy $4 $3 1 -$5
    StrCmp $4 "" error
    StrCmp $4 $0 0 loop3
     IntOp $5 $5 - 1
     StrCpy $3 $3 "" -$5
   Goto exit
error:
  StrCpy $3 error
exit:
  StrCpy $0 $3
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0 ;output string
FunctionEnd

-Stu (Afrow UK)