[jawsscripts] Re: Character Index in String?
- From: "john.falter" <john.falter@xxxxxxxxxxx>
- To: <jawsscripts@xxxxxxxxxxxxx>
- Date: Fri, 23 Jan 2009 14:14:20 -0500
Some of my documents have unwanted "255" characters. I use this script with
JAWS 10 to remove them.
Script clean ()
;alt shift r
let gs1 = GetClipboardText () ; clipboard to input string
let gs3 = "" ; initialize output string
let glen = StringLength (gs1)
SayInteger (glen) ; how many characters at start
; tell me if cleaning is necessary
if StringContains (gs1, "\255") then say ("yes",1) endif
; stop when no more 255 characters
while StringContains (gs1, "\255")
let gpos = StringContains (gs1, "\255") ; gpos is the position of the next
255
;SayInteger (gpos) during testing
; copy to output all characters up to but not including 255
let gs3 = gs3 + SubString (gs1, 1, gpos-1)
; delete from input all characters up to and including the 255
LET GS1 = stringChopLeft (gs1, gpos)
endwhile
CopyToClipboard (gs3) ; output string to clipboard
let glen = StringLength (gs3) ; how many remaining characters
SayInteger (glen)
EndScript
----- Original Message -----
From: "Donald Marang" <donald.marang@xxxxxxxxx>
To: <jawsscripts@xxxxxxxxxxxxx>
Sent: Thursday, January 22, 2009 3:39 AM
Subject: [jawsscripts] Re: Character Index in String?
> Surprisingly, that is not the way it works for me in JAWS 10! I think I
> recall every other language library behabing that way. Of course, that
> has
> been a long time. Maybe my mind is foggy. The StringContainsChars
> function
> strictly returns a 1 or 0, just as it is documented. But I need a
> function
> that returns the index of the character in the string. In most languages,
> even APL, there is ann easy way to get the index of a character in a
> string.
> Below is a section of code where I was doing this experiment:
>
> SayString ("You have selected " + sChoiceButton)
> Let iChop = StringContainsChars (sChoiceButton, ":")
> SayString ("find index = " + IntToString (iChop))
> If iChop Then
> Let sChoiceButton = StringLeft (sChoiceButton, iChop)
> SayString (" String chopped to: " + sChoiceButton)
> EndIf
>
> Thanks for your help!
>
> Don Marang
>
>
> ----- Original Message -----
> From: "john.falter" <john.falter@xxxxxxxxxxx>
> To: <jawsscripts@xxxxxxxxxxxxx>
> Sent: Wednesday, January 21, 2009 11:18 PM
> Subject: [jawsscripts] Re: Character Index in String?
>
>
>> Try:
>> let int1 = stringContains(string1, "something")
>> The position of something will be in int1.
>> int1 will be zero if something is not found.
>>
>> ----- Original Message -----
>> From: "Donald Marang" <donald.marang@xxxxxxxxx>
>> To: <jawsscripts@xxxxxxxxxxxxx>
>> Sent: Wednesday, January 21, 2009 10:06 PM
>> Subject: [jawsscripts] Character Index in String?
>>
>>
>>> Hopefully, this is an easy question for you guys.I want to remove all
>>> characters in a string after the occurrence of a certain character, lets
>>> say ":", and including that character. I looked at the StringLeft and
>>> StringContainsChars functions. To have these two functions work
>>> together,
>>> the StringContainsChars would need to return the index where the
>>> character
>>> was found rather than just a Boolean True or false. Are there more
>>> appropriate functions or methods to accomplish this simple task.
>>> For instance I want to transform the string
>>> "Menu:only available in To DVD mode"
>>> to
>>> "Menu"
>>>
>>> Don Marang
>>>
>>>
>>> __________
>>> Visit and contribute to The JAWS Script Repository
>>> http://jawsscripts.com
>>>
>>> View the list's information and change your settings at
>>> http://www.freelists.org/list/jawsscripts
>>>
>>
>> __________
>> Visit and contribute to The JAWS Script Repository http://jawsscripts.com
>>
>> View the list's information and change your settings at
>> http://www.freelists.org/list/jawsscripts
>>
>
> __________
> Visit and contribute to The JAWS Script Repository http://jawsscripts.com
>
> View the list's information and change your settings at
> http://www.freelists.org/list/jawsscripts
>
__________
Visit and contribute to The JAWS Script Repository http://jawsscripts.com
View the list's information and change your settings at
http://www.freelists.org/list/jawsscripts
Other related posts: