Slice: Cut string out of string: 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 simply cuts a string from another string.
This simply cuts a string from another string.
Line 58: Line 62:
  Exch $R0 ; output string
  Exch $R0 ; output string
FunctionEnd</highlight-nsis>-Stu
FunctionEnd</highlight-nsis>-Stu
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 03:04, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

This simply cuts a string from another string.

Usage

Push "String" ; ...to cut from
Push "...Another String"
 Call Slice
Pop $R0 ; New string: "...Another "
Pop $R1 ; Cut done? 0/1

The Function

Function Slice
 Exch $R0 ; input string
 Exch
 Exch $R1 ; to cut
 Push $R2
 Push $R3
 Push $R4
 Push $R5
 
 StrLen $R3 $R1
 StrCpy $R4 -1
 StrCpy $R5 0
 
 Loop:
 
  IntOp $R4 $R4 + 1
  StrCpy $R2 $R0 $R3 $R4
  StrCmp $R2 "" Done
  StrCmp $R2 $R1 0 Loop
 
   StrCpy $R5 1
 
   StrCmp $R4 0 0 +3
    StrCpy $R1 ""
    Goto +2
   StrCpy $R1 $R0 $R4
   StrLen $R2 $R0
   IntOp $R4 $R2 - $R4
   IntOp $R4 $R4 - $R3
   IntCmp $R4 0 0 0 +3
    StrCpy $R2 ""
    Goto +2
   StrCpy $R2 $R0 "" -$R4
   StrCpy $R0 $R1$R2
 
 Done:
 StrCpy $R1 $R5
 
 Pop $R5
 Pop $R4
 Pop $R3
 Pop $R2
 Exch $R1 ; slice? 0/1
 Exch
 Exch $R0 ; output string
FunctionEnd

-Stu