Get first part of a string: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Adding new author and category links.)
 
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 allows you to get the part of the input string before the first space " " or before a character of your choice.
This script allows you to get the part of the input string before the first space " " or before a character of your choice.
Line 42: Line 40:
-Stuart
-Stuart


[[{{ns:14}}:String Functions]]
[[Category:String Functions]]

Latest revision as of 12:22, 24 June 2005

Author: Afrow UK (talk, contrib)


Description

This script allows you to get the part of the input string before the first space " " or before a character of your choice.

Usage

Push "HelloAll I am Afrow UK, and I love NSIS" ; Input string
Call GetFirstStrPart
Pop "$R0"

Where $R0 will now be "HelloAll"

The Function

Function GetFirstStrPart
  Exch $R0
  Push $R1
  Push $R2
  StrLen $R1 $R0
  IntOp $R1 $R1 + 1
  loop:
    IntOp $R1 $R1 - 1
    StrCpy $R2 $R0 1 -$R1
    StrCmp $R2 "" exit2
    StrCmp $R2 " " exit1 ; Change " " to "\" if ur inputting dir path str
  Goto loop
  exit1:
    StrCpy $R0 $R0 -$R1
  exit2:
    Pop $R2
    Pop $R1
    Exch $R0
FunctionEnd

Written by me (Afrow UK)

-Stuart