Source language: Translate to:

spell

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

spell

Postby Neobook » Sun Oct 22, 2006 9:16 am

Hi,

How can I do a speller ?

It's mean, when I write a word, for example : eat

in the result it's : e-a-t

Thanks
Neobook
 
Posts: 131
Joined: Sat Jul 01, 2006 7:07 am

Postby Sam Cox » Sun Oct 22, 2006 4:57 pm

If I understand correctly, you'd like a function that puts a dash between each letter ... something like:
Code: Select all
Call "StrExplode" "eat" "-" "[result]"

and [result] = "e-a-t".

Here is a function that does this:
Code: Select all
{NeoBook Function}
Version=5.52
Param=[%input]|Text|Input string of characters
Param=[%sep]|Text|Character Separator (blank is okay)
Param=[%return]|Variable|Variable to receive output string
{End}
strlen "[%input]" "[:len]"
if "[:len]" ">" "0"
  setvar "[:temp]" ""
  loop "1" "[:len]" "[:n]"
     substr "[%input]" "[:n]" "1" "[:char]"
     setvar "[:temp]" "[:temp][%sep][:char]"
  endloop
  strlen "[%sep]" "[:len]"
  substr "[:temp]" "[:len]+1" "999999" "[:temp]"
  setvar "[%return]" "[:temp]"
else
  setvar "[%return]" ""
endif
return

The function StrExplode takes three parameters:
Code: Select all
Call "StrExplode" "input" "separator" "[ResultVariable]"

a) an input string in the form of a constant such as "eat" or a variable such as [TextEntry1].

b) a separator string to place between each character; the separator string can be empty (in which case the result is the same as the input), and the separator can be any string of 1 or more characters.

c) The answer is returned in the third parameter which must be a variable.

Examples:
Code: Select all
Call "StrExplode" "magoo" "-" "[Result]"
.. [Result] = "m-a-g-o-o"

Call "StrExplode" "magoo" "--" "[Result]"
.. [Result] = "m--a--g--o--o"

Call "StrExplode" "magoo" "," "[Result]"
.. [Result] = "m,a,g,o,o"

Call "StrExplode" "magoo" "[#32]" "[Result]"
.. [Result] = "m a g o o"

Call "StrExplode" "magoo" "" "[Result]"
.. [Result] = "magoo"

Others using this function might want to explode a string into an array of characters. Here's how:
Code: Select all
SetVar "[Sep]" "[#255]"
Call "StrExplode" "[Input]" "[Sep]" "[temp]"
StrParse "[temp]" "[Sep]" "[Char]" "[CharCount]"

where the value of [Sep] is chosen to be different than any expected run of input characters. The result of running this code is an array [Char1], [Char2], [Char3], ... of [CharCount] variables each containing one of [Input]'s letters.

Edit: Added missing punctuation.
Last edited by Sam Cox on Mon Oct 23, 2006 11:16 am, edited 1 time in total.
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Postby Aaron » Mon Oct 23, 2006 2:16 am

You forgot a quotation mark in StrLen after the EndLoop.
Aaron
 
Posts: 13
Joined: Fri Apr 01, 2005 7:16 am
Location: Spain

Postby Sam Cox » Mon Oct 23, 2006 11:17 am

Thank you Aaron,
-- Sam
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Postby Neobook » Mon Oct 23, 2006 11:39 am

Hi

Would you send me an example please, because I don't understand.

Thanks
Neobook
 
Posts: 131
Joined: Sat Jul 01, 2006 7:07 am

Postby Sam Cox » Mon Oct 23, 2006 3:00 pm

Copy the following code into a file named "StrExplode" in the C:\Program Files\Neobook 5\Functions directory. The filename must have no extension. That is, the filename must be "StrExplode" and not, for example, "StrExplode.txt".
Code: Select all
{NeoBook Function}
Version=5.52
Param=[%input]|Text|Input string of characters
Param=[%sep]|Text|Character Separator (blank is okay)
Param=[%return]|Variable|Variable to receive output string
{End}
strlen "[%input]" "[:len]"
if "[:len]" ">" "0"
  setvar "[:temp]" ""
  loop "1" "[:len]" "[:n]"
     substr "[%input]" "[:n]" "1" "[:char]"
     setvar "[:temp]" "[:temp][%sep][:char]"
  endloop
  strlen "[%sep]" "[:len]"
  substr "[:temp]" "[:len]+1" "999999" "[:temp]"
  setvar "[%return]" "[:temp]"
else
  setvar "[%return]" ""
endif
return

To be sure that the "StrExplode" function file is in the right place, start Neobook5 and select Options>>Function Library. Scroll to the "StrExplode" entry in the Available Function list. Double click the "StrExplode" entry to see the source code. DON'T CHANGE ANYTHING. Just click the "Cancel" button and then the "Close" button to return to Neobook5.

Create a new publication with three objects:

a) a TextEntry1 object
b) a Simple Text object displaying the variable [Letters]
c) a Button object with this code
Code: Select all
Call "StrExplode" "[TextEntry1]" "-" "[Letters]"

Run the program. Type your name into the TextEntry object and press the button. You should see your name with dashes between each of the letters.
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Postby virger » Mon Oct 23, 2006 6:01 pm

{NeoBook Function}
Version=5,51
Comment=Param1==The Var to EXPLODE|Param2==The SEPARATOR
Param=[%_v]|Variable|Variable To Change
Param=[%_sp]|Variable|Separator
Param=[%_rt]|Variable|Result
{End}
setvar "[%_rt]" "[%_v]"
strlen "[%_v]" "[_ln]"
if "[_ln]" ">" "0"
strlen "[%_sp]" "[_ms]"
loop "2" "[_ln]+(([_ln]-1)*[_ms])" "[_c]"
StrIns "[%_sp]" "[%_rt]" "[_c]" "[%_rt]"
math "[_c]+[_ms]" "" "[_c]"
endloop
endif
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Postby Neobook » Tue Oct 24, 2006 10:23 am

Thank you very much
Neobook
 
Posts: 131
Joined: Sat Jul 01, 2006 7:07 am


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 3 guests