SearchStr case sensitive?
Moderator: Neosoft Support
SearchStr case sensitive?
Hi again.
Is there a way to do a word search using "SearchStr" with out having to worry about typing the word with the correct case?
I have many words in the array but if I want to find all the words named Printer as a loop runs, if I type in "Printer" with the first letter P as a capital, if there are also other words the same but they had been added as "printer" with the first letter lower case, these will get missed. And the other way round the ones with the capital are missed!
It appears that the "SearchStr" does not offer the case sensitive option like in NeoBook.
Is it possible to add this feature?
Is there a way to do a word search using "SearchStr" with out having to worry about typing the word with the correct case?
I have many words in the array but if I want to find all the words named Printer as a loop runs, if I type in "Printer" with the first letter P as a capital, if there are also other words the same but they had been added as "printer" with the first letter lower case, these will get missed. And the other way round the ones with the capital are missed!
It appears that the "SearchStr" does not offer the case sensitive option like in NeoBook.
Is it possible to add this feature?
Re: SearchStr case sensitive?
PaulTomo:
In place of your case-sensitive SearchStr like this ...... which will set [SearchResult] to 26 ... do something like this ...... which will set [SearchResult] to 9
Until it is added, here is a workaround ...It appears that the "SearchStr" does not offer the case sensitive option like in NeoBook.
Is it possible to add this feature?
In place of your case-sensitive SearchStr like this ...
Code: Select all
SetVar [SourceString] "Print on printer labelled Printer1"
SetVar [TextToFind] "Printer"
SearchStr "[TextToFind]" "[SourceString]" [SearchResult]
AlertBox "SearchStr" "for: [TextToFind]<br/>in: [SourceString]<br/>result: [SearchResult]" ""
Code: Select all
SetVar [SourceString] "Print on printer labelled Printer1"
SetVar [TextToFind] "Printer"
BeginJS
var ttf = new RegExp($rootScope.TextToFind, "i");
$rootScope.SearchResult = $rootScope.SourceString.search(ttf);
EndJS
AlertBox "jsSearchStr" "for: [TextToFind]<br/>in: [SourceString]<br/>result: [SearchResult]" ""
Re: SearchStr case sensitive?
Thanks Gaev,
Yes that did it, tweaked the variables so they worked with JS, added your suggestion to my loop and both upper and lower case results now returned, Phew!.
Many Thanks for you help and just wanted to mention what a good place this Forum is, everyone is so helpful and actually do give answers to the questions, unlike others I sometimes use.
Cheers,
Paul (Tomo)
Yes that did it, tweaked the variables so they worked with JS, added your suggestion to my loop and both upper and lower case results now returned, Phew!.
Many Thanks for you help and just wanted to mention what a good place this Forum is, everyone is so helpful and actually do give answers to the questions, unlike others I sometimes use.
Cheers,
Paul (Tomo)
-
- NeoSoft Team
- Posts: 5628
- Joined: Thu Mar 31, 2005 10:48 pm
- Location: Oregon, USA
- Contact:
Re: SearchStr case sensitive?
Gaev,
Would it be better to use something like
[var] = sourceText.toLowerCase().indexOf(textToFind.toLowerCase());
as opposed to the RegExp/Search method?
indexOf might be slightly faster, but would RegExp/Search work better with some languages?
Would it be better to use something like
[var] = sourceText.toLowerCase().indexOf(textToFind.toLowerCase());
as opposed to the RegExp/Search method?
indexOf might be slightly faster, but would RegExp/Search work better with some languages?
NeoSoft Support
Re: SearchStr case sensitive?
Dave:
My response was one of "bull in the china shop" ... i.e. if not available as NeoScript command, how about Javascript ... then realized that "case insensitivity specification" is done via a "regex" object.
But I should have been thinking about the obvious approach of comparing lowercase against lowercase ... for people who are not comfortable outside the NeoScript environment, this (all NeoScript) code works too ...
May only be half as "lightening fast" as my previous suggestion ... but in my book, ease of development/maintenance trumps one micro-second of run time.
With split second responses from Javascript, I never considered "Speed of Execution" ... and I have no expertise to determine"Better Choice" ... in fact, I did not even consider indexOf().Would it be better to use something like
[var] = sourceText.toLowerCase().indexOf(textToFind.toLowerCase());
as opposed to the RegExp/Search method?
indexOf might be slightly faster, but would RegExp/Search work better with some languages?
My response was one of "bull in the china shop" ... i.e. if not available as NeoScript command, how about Javascript ... then realized that "case insensitivity specification" is done via a "regex" object.
But I should have been thinking about the obvious approach of comparing lowercase against lowercase ... for people who are not comfortable outside the NeoScript environment, this (all NeoScript) code works too ...
Code: Select all
SetVar [SourceString] "Print on printer labelled Printer1"
SetVar [TextToFind] "Printer"
StrLower "[SourceString]" [SourceStringLower]
StrLower "[TextToFind]" [TextToFindLower]
SearchStr "[TextToFindLower]" "[SourceStringLower]" [SearchResult]
AlertBox "SearchStr" "for: [TextToFind]<br/>in: [SourceString]<br/>result: [SearchResult]" ""
-
- NeoSoft Team
- Posts: 5628
- Joined: Thu Mar 31, 2005 10:48 pm
- Location: Oregon, USA
- Contact:
Re: SearchStr case sensitive?
I don't think speed of execution would be noticeable here either. Maybe an option should be added to SearchStr so that it can be case sensitive or insensitive depending on the need?
NeoSoft Support
Re: SearchStr case sensitive?
Dave:
But for now, this code ...... can be placed in a Subroutine that can then be called with a command like ...
While on the subject of Subroutines ...
1) When I included the Return command in one of them, NeoAppBuilder said that it required a parameter/value ... I entered 5 and the syntax error disappeared ... but I am not sure "how the calling command (code section) would access this value".
2) The App Properties section of NeoAppBuilder had a Tab called Libraries ... where a developer can include (among other things) a file containing commonly deployed Javascript functions (to be included in this Project) ... would be nice to have a similar facility to include "commonly deployed Subroutines".
If you consider this suggestion, it would be nice to be able to ...
a) Create, Save and Edit multiple Subroutine files
b) specify inclusion of one/more of these files in a specific project
Yes, I thought you would make that change in the near future ... just like with NeoBook's command.Maybe an option should be added to SearchStr so that it can be case sensitive or insensitive depending on the need?
But for now, this code ...
Code: Select all
StrLower "[SourceString]" [SourceStringLower]
StrLower "[TextToFind]" [TextToFindLower]
SearchStr "[TextToFindLower]" "[SourceStringLower]" [SearchResult]
Code: Select all
SearchStrNoCase "Print on printer labelled Printer1" "Printer"
1) When I included the Return command in one of them, NeoAppBuilder said that it required a parameter/value ... I entered 5 and the syntax error disappeared ... but I am not sure "how the calling command (code section) would access this value".
2) The App Properties section of NeoAppBuilder had a Tab called Libraries ... where a developer can include (among other things) a file containing commonly deployed Javascript functions (to be included in this Project) ... would be nice to have a similar facility to include "commonly deployed Subroutines".
If you consider this suggestion, it would be nice to be able to ...
a) Create, Save and Edit multiple Subroutine files
b) specify inclusion of one/more of these files in a specific project
-
- NeoSoft Team
- Posts: 5628
- Joined: Thu Mar 31, 2005 10:48 pm
- Location: Oregon, USA
- Contact:
Re: SearchStr case sensitive?
Return really isn't necessary in NeoAppBuilder subroutines since each sub is isolated from the others unlike NeoBook. However, you can use Return to bail out of a script provided that you add a parameter. For example:1) When I included the Return command in one of them, NeoAppBuilder said that it required a parameter/value ... I entered 5 and the syntax error disappeared ... but I am not sure "how the calling command (code section) would access this value".
Return false
or
Return 0
The parameter will be ignored.
The Return parameter IS (or will be) used in certain events. Currently, the only event that uses the Return parameter is the Form object's 'submit' event. Returning 'false' in the submit event cancels the form action while returning 'true' processes the action.
Yes, that's a good idea. Eventually, an import/export option will be added, but some type of reusable library feature would be useful too. I don't want the program to become overly complicated - though that ship may have sailed. The envisioned plug-in feature would also allow the addition of custom functions similar to NeoBook.2) The App Properties section of NeoAppBuilder had a Tab called Libraries ... where a developer can include (among other things) a file containing commonly deployed Javascript functions (to be included in this Project) ... would be nice to have a similar facility to include "commonly deployed Subroutines".
NeoSoft Support