SearchStr case sensitive?

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

Locked
User avatar
PaulTomo
Posts: 63
Joined: Tue Apr 28, 2009 1:15 am
Location: UK

SearchStr case sensitive?

Post by PaulTomo »

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?
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: SearchStr case sensitive?

Post by Gaev »

PaulTomo:
It appears that the "SearchStr" does not offer the case sensitive option like in NeoBook.

Is it possible to add this feature?
Until it is added, here is a workaround ...

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]" ""
... which will set [SearchResult] to 26 ... do something like this ...

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]" ""
... which will set [SearchResult] to 9
User avatar
PaulTomo
Posts: 63
Joined: Tue Apr 28, 2009 1:15 am
Location: UK

Re: SearchStr case sensitive?

Post by PaulTomo »

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)
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: SearchStr case sensitive?

Post by Neosoft Support »

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?
NeoSoft Support
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: SearchStr case sensitive?

Post by Gaev »

Dave:
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?
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().

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]" ""
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.
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: SearchStr case sensitive?

Post by Neosoft Support »

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
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: SearchStr case sensitive?

Post by Gaev »

Dave:
Maybe an option should be added to SearchStr so that it can be case sensitive or insensitive depending on the need?
Yes, I thought you would make that change in the near future ... just like with NeoBook's command.

But for now, this code ...

Code: Select all

StrLower "[SourceString]" [SourceStringLower]
StrLower "[TextToFind]" [TextToFindLower]
SearchStr "[TextToFindLower]" "[SourceStringLower]" [SearchResult]
... can be placed in a Subroutine that can then be called with a command like ...

Code: Select all

SearchStrNoCase "Print on printer labelled Printer1" "Printer"
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
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: SearchStr case sensitive?

Post by Neosoft Support »

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 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:

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.
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".
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.
NeoSoft Support
Locked