Here's a nice efficient way to find the location of the space before
every (lowercase) n in your string. Note, though, that it will not
return the same space more than once, even if your string is something
like "I enjoy running" with three Ns in one word. Note, too, that the
first character in the string is at position 0. This is different from
the Instr function, which returns values beginning at 1. To get a
compatible value, add 1 to the FirstIndex property.
If you want to include uppercase letters, too, you'd set the IgnoreCase
property in the re object to true.
If you just want the first match, set the global property of the re
object to false.
(This is a transcript from immed in no-output-window mode; obviously
you'll have to adapt it for your own purposes.)
set re= new regexp
re.pattern = " [^ ]*n"
re.global = true
str = "the rain is falling"
set matches = re.execute(str)
print matches.count
2
for each match in matches : print match.firstindex & " " & match.value
: next
3 rain
11 fallin
str = "I enjoy running"
set matches = re.execute(str)
print matches.count
2
for each match in matches : print match.firstindex & " " & match.value
: next
1 en
7 runnin
On 8/21/2011 2:38 PM, Chip Orange wrote:
Hi David,
your first question: the function you're looking for is "replace()".
it has 3 parameters:
replace(<string to work on>, <string to search for>, <string to
replace with>)
and it returns a string with the replacement.
Your second question:
you can search from right to left using the inStrRev() function; so,
if you locate the letter "n" in your example, then you could use it's
location, along with the left() function, to isolate the beginning
part of the string into it's own variable. you could then use
inStrRev() on this string, to search backwards for a space, and you
would get the location of the space just before the word "rain" since
you're working with just the partial segment.
hth,
Chip
------------------------------------------------------------------------
*From:* David [mailto:[email protected]]
*Sent:* Sunday, August 21, 2011 9:31 AM
*To:* [email protected]
*Subject:* Re: Guess I am on the wrong Event?
Thanks, Chip!
You really got me going now. Seems I am closing in on something here
with my app.
I do have a couple more questions, for you app-techies.
First of all, is there a replacing command - in VBS? I.e, if I have
the string:
The sun is shining today.
And I want to replace the word IS, with the words HAS BEEN - hence my
string would read:
The sun has been shining today.
Of course, I could have meddled with some MID-commands here, but just
wondered if there is an easier way. My memory tells me, I did read
about a Replace command somewhere, but can't find that documentation
now; so hope for someone of you to have better memory. If there is,
please provide the full syntax for the command.
My other question, is maybe somehow more tricky. If I find a character
- by using the InStr command - inside a string. Maybe that character
is in the middle of a word. I want to find the space character
immediately before the word. Let's have an example:
I have the string:
The rain is falling.
I want to find - and speak - the word that holds the character "n" in
it; in this case the first word would be RAIN.
I use the following commands:
S = "The rain is falling."
X = InStr( S, "n")
Now I found the first position of the character N. But is there a good
way of finding the beginning of that word "rain"? Only way I can come
up with, is to make some kind of a loop, testing each character to the
left of the N, until I hit an empty (space) character. Then add on 1,
so as to land on the first character of the word. Then, of course, if
I want the full word, I would need to do the same to the right of the
N character. Finally, with my beginning and ending positions set, to
use the MID-command, to copy the word. Anyone else, have an idea of an
easy way to find the beginning of the word?
Thanks again,
----- Original Message -----
*From:* Chip Orange <mailto:[email protected]>
*To:* [email protected] <mailto:[email protected]>
*Sent:* Sunday, August 21, 2011 4:06 AM
*Subject:* RE: Guess I am on the wrong Event?
Hi David,
your idea is correct, but you've got the wrong event of the speech
object. There are actually 9 of these events, each one
representing a different type of processing which can be done on
the string about to be spoken.
These events aren't documented well in my opinion (there's very
little explanation as to what exactly each one does). There's
also little explanation which explains that if you want to
intercept speech and do processing on it, you'll need to figure
out which kind of processing you are doing (type being compared to
the type of processing represented by these 9 different events).
Since you are wanting to do something based on a single character
which is not alpha-numeric, you'll need to use the
OnProcessCharacterDictionaries event, in order to be able to see
the string about to be spoken, before the punctuation is replaced
by text strings.
Just change events and I think it will work for you.
hth,
Chip
------------------------------------------------------------------------
*From:* David [mailto:[email protected]]
*Sent:* Saturday, August 20, 2011 6:19 PM
*To:* [email protected]
*Subject:* Guess I am on the wrong Event?
Hi scripters,
I am trying to make an app that handles fractional numbers. That
is, have it speak the word "Fractional", when it reaches numbers
like 1/4. Below is a snip of my code. My thought was to connect to
the Speech/OnSpeak event, and simply check if there is a SLASH in
the original string. But that seems not to work. When things like
1/2, 2/3 or 3/4 occurs, it seems that the OnSpeak string is broken
into two seperate strings, by Window-Eyes. Not sure why GW would
do such a thing, but that seems to be the case. In other words,
the 1/3, will be broken into two strings: "1", and "3". This
causes, far as I can see, Window-Eyes not to ever 'see' the slash
inbetween; hence my code never works.
Am I connecting to the wrong event? Is there a better approach to
the matter?
---Snip of code---
ConnectEvent Speech, "OnSpeak", "MOnSpeak"
Function MOnSpeak( OriginalString )
If InStr(OriginalString, "4") Then OriginalString = "Fractional,
" & OriginalString
MOnSpeak = OriginalString
End Function 'MOnSpeak.
----End of snip----
Speak "Fractional, is running."