Skip to content
⌘ NSIS Forum Archive

string functions

117 posts

deguix#
* finding index of char/substr in string
Maybe a change to StrStr to do that, so I have to work a little bit...

* finding first occurence char from subset in string starting from index.
You can do this using StrCpy to customize where it will start and use StrStr Function.

* replacing char/substring in string
Use StrReplace Function.

* conversion to/from C-style strings (for easier using strings in Windows functions).
Hmmmm... maybe using System plugin or Math plugin. I will try to search.

* concatenating string (in current system name of veriable is joined with following text, which can make trouble in some cases) OR append-to-text function.
One command resume it all: StrCpy.

PS. How to display path text from string char in Label control of dialog window? I have to convert it to C-style string; creating such function in current script would be quite painful.
Use NSISToIO inside header file. (I don't know if this is right if you want to do that in a normal dialog from Windows or something)
kichik#
conversion to/from C-style strings (for easier using strings in Windows functions).
NSIS uses C-style strings. What do you mean by this?
deguix#
Hehehe, I bought a new game and I and my brother couldn't stop to play it until now... but it is nearly done. 6:00 AM of tomorrow is done, or more soon if it is possible... (sharing pc problems, you know)
deguix#
Version 1.00 done. Included the header file and manual.

Changes:

- Added documentation.
- Renamed header file to "StrFunc.nsh".
- Added 1 function, StrLoc.
- Modified StrStrAdv, removed some lines.
- Fixed StrTok, 2 simple numbers made it loop everytime.
- Fixed some small issues in the header file.
kichik#
Thanks.

I tried to write an example file for the header file but stumbled upon a few problems. The example file, including the described problems is attached.

StrLoc doesn't seem to function when the string it searches for is larger than the string it searches in. I found this because I got confused of the readme which states the usage line is:

${StrLoc} ResultVar String StrToSearchIn Direction

On first look it looks like I'm supposed to put the string that I want searched in StringToSearchIn, but it's the other way around. How about SearchIn SearchFor?

According to my understanding, the next line should return "abc", but it doesn't:

${StrStrAdv} $0 "abcabcabc" "abc" "<" ">" "0" "1"

It returns an empty string. If I search for the second occurrence of "abc" in "abcabcabc", starting from the right position, it should find the second set of "abc", but it doesn't.

StrSort doesn't seem to want to search for more than one char (line 136). It also has a problem if you want to search for "error" (line 139).

And last but not least, StrTok gets stuck in an endless loop if the token number is 0.
deguix#
Version 1.01, all bugs you said are fixed:

- Fixed Documentation about StrSort and StrTok.
- Fixed StrTok default value for the string part. Now it's "L".
- Fixed StrStrAdv fixed wrong search when had a combination of same substrings one after another in a string.
- Fixed StrLoc, when a string isn't found, don't return any value at all.

Read the manual for see more details.
kichik#
StrLoc and StrSort are still not working right. The documentation of StrSort got mixed up. It's talking about StringToSearch but there is no such parameter on the usage line. Example attached.
deguix#
But I did another version, adding my new AdvStrSort, and fixing spelling errors in the documentation:

New in 1.02 - 02/07/04:
-----------------------

- Fixed Documentation about StrLoc. "Direction" is really
"OffsetDirection".
- Added my new AdvStrSort, and removed the old one.
I tested the new function all night until now, and it's working.

Kichik, don't dispair. Use the same example you're using just adding the new qualities of AdvStrSort (called inside as StrSort). Nothing was changed in other functions.

Example of use - StrSort:

${StrSort} $0 "This is just an example" " just" "" "ple" "0" "0"

$0 = "This is an exam"

;"This is just an example" is the String
;" just" is the CenterStr
;"" is the LeftStr
;"ple" is the RightStr
;Display LeftStr and RightStr FALSE
;Display CenterStr FALSE
kichik#
Are you sure you want to keep the old version of the readme and not use my changes?

This StrSort call fails:

${StrSort} $0 "This is just an example" "j" "" "" "1" "0"
StrCmp $0 "This is ust an example" 0 strsorterror
deguix#
Yep. Because the last "0" says that will not include the CenterStr.

I did your changes in my documentation. Only if had any more changes you did in other functions but StrLoc...

You can do any changes to it, I can't go to Internet 9:00AM to 10:00PM (but sometimes I can with a little help...).
kichik#
But it does include CenterStr, that's the problem.

The zip you've attached doesn't include a single change I made to the readme.
deguix#
Fixed and included your changes in the readme.
Spatacoli#
thanks deguix and Kichik, I've been using these string functions with the new build and they work great! Thank you for your hard work.
evilO#
Using Str functions in the uninstaller

Hi everyone !

First of all, congratulation to the NSIS dev team : I've used NSIS two years ago to build an installer for my university project, it worked great for my needs..

When I started using it again a few months ago, I couldn't believe how nicer it became! I'm glad the version 2.0 has been released, keep up gooooood work 👍 !


Now here is my question.

@deguix: no doubt your string functions header is useful, but is there an easy way to use these functions in the uninstaller ? Euh, maybe I missed something ?


Thanks 🙂

evilO/Olive
Comm@nder21#
sure.
use it in the same way like in the installer.
just in an "un.xyz" section, or in the "Uninstaller"-section, or any related function.
evilO#
Err, well, I've already tried before to post in this thread, but obviously the compiler complains about the functions not starting with "un."...

Apparently it's not possible to use them in the uninstaller without having to modify the (neatly designed) header.

Am I wrong ? 😕

evilO/Olive
deguix#
I'll fix that and another bug tomorrow.

To everyone know, the reason I'm slow in responses and fixes is that I have 2 school tests tomorrow(school time: 8:00 AM to 2:15 PM), I have 2 school projects to do, I share the computer with 3 more persons, my internet time is limited 5AM to 7AM, sometimes I use at 10PM, and rarely I can use another times.

So please, BE PATIENT.

Just that for now...
evilO#
Deguix : don't worry, there is no hurry .. I could'nt provide fixes and answers with half of your amount of work 😛

So ... good luck for your exams 🙂

evilO/Olive
deguix#
Just ignore my last message...

1.03 - 02/12/2004

- Added commands support for uninstall sections and functions.
- Fixed variables switch in "StrLoc" and "StrTok" after using these.
Read the manual first to use commands supported for uninstall section, nothing changed with install supported commands.

The file:
evilO#
Hi Deguix ! Thanks a lot for your fix, but, err, I hate to say that but I still have troubles... 🙁

1) I Have tried the sample provided in the doc (2.2 How To Use Commands In Uninstall Sections and Functions) :
it does work using either ${StrStr} or ${UnStrStr}, but doesn't work if I use both 🤪 :

!insertmacro: macro "FUNCTION_STRING_StrStr" requires 0 parameter(s), passed 3!

2) There is a "mistake" for the function StrTok, the second macro used to call the function is :
!macro FUNCTION_STRING_StrTok_Call
instead of
!macro FUNCTION_STRING_UnStrTok_Call


evilO/Olive
evilO#
Euh, sorry but I think I've just found two other "mistakes" in the following macros:

1) in "FUNCTION_STRING_StrStrAdv":

; ...
!ifdef FUNCTION_STRING_UninstSupport
!undef UnStrStrAdv
!define UnStrStrAdv "!insertmacro FUNCTION_STRING_UnStrStrAdv_Call"
Function un.AdvancedStrStr
!else
!undef StrStrAdv
!define StrStrAdv "!insertmacro FUNCTION_STRING_StrStrAdv_Call"
Function AdvancedStrStr
!endif

Function AdvancedStrStr ; <-- should be removed
; ...

2) Same for "FUNCTION_STRING_StrLowerCase"


Thanks 🙂

evilO/Olive
deguix#
ammm.... And I forgot to say: "I didn't test this feature", so can have a lot of mistakes in there... but anyways, thanks evilO. Same version 1.03.
evilO#
Well, Deguix, it seems that I still can't get your example to work... 😕

There is apparently no way to use both functions in the same script. I mean, ${StrStr} AND ${UnStrStr} for instance. I've attached the output if that can help.

Well, I'm sorry to be such a pain 🙁

evilO/Olive

PS: Have a good week-end 🙂
deguix#
Ohhh, now I remember, is a define to indentify if a function inserter command has been called more than one time... When I define it before calling the inserter macro, it skips the code. EDIT: When you call the ${StrStr} and ${UnStrStr} is like calling it two times (so you can use after ${UnStrFunc} the same ${StrStr} that will be the same thing as ${UnStrStr}).

I'll publish the fix when I exit from school (I'm there now) and when I have the first opportunity to connect to internet in home.
deguix#
The fix is here (I think), test it. Same version number 1.03.

(from those tests I mention before, all of them were 100 or above (from bonus questions))