[jawsscripts] inserting a comma after first word in a string?

  • From: "Geoff personal" <gch@xxxxxxxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Tue, 14 Apr 2009 18:58:56 +1000

Well Mr Sean, just here to tell you that I've finally gotten around to 
testing this so-called untested wonderful code of yours below, and it works 
a jolly treat!

Wow! two lines of magic code and one gets the results one's after! it's all 
in the magic juggling of knowledge eh?
thank you soo so so so much for this.  I think it will make firstPass 
comprehension of the street number and name, far more intelligible for users 
due to your ministrations!

my sincereest thanks to you!just Awesome!
 and I'm starting to get the nuts and bolts of it a bit more too.
Haven't got heaps of time right now to study it into my head huge time,
and I know I need to practise utilizing these things more so I can really 
get the stuff down inside my head,, but, I did try and grasp it a little 
more than just copying the raw code inserting my own string names etc.

I think I may get it eventually if I keep using the concepts more eh.

Thanks again.

Geoff c.
----- Original Message ----- 
From: "Geoff personal" <gch@xxxxxxxxxxxxxxxx>
To: <jawsscripts@xxxxxxxxxxxxx>
Sent: Monday, April 06, 2009 5:14 PM
Subject: [jawsscripts] Re: inserting a comma after first word in a string?


> wow sean! this is wild man!
> Exactly what I needed to be learning! and you've set things out so 
> logically
> and helpfully!
>
> thank you so much for this!
> I'll go away and study it a bit, I'm slow at grasping these things eh,
> and hopefully now I'll be able to do it. I'll let you know how I go with 
> it
> tomorrow.
>
> Thanks again for all the great code examples and explanations!
>
> Geoff c.
>
>
> ----- Original Message ----- 
> From: "Sean Randall" <seanr@xxxxxxxxxxxxxxx>
> To: <jawsscripts@xxxxxxxxxxxxx>
> Sent: Monday, April 06, 2009 4:57 PM
> Subject: [jawsscripts] Re: inserting a comma after first word in a string?
>
>
>> Geoff,
>>
>> String manipulation is an important topic to get your head around, and
>> given
>> what you've been doing previously, you should quite easily be able to
>> grasp
>> the concepts.
>>
>> You can use the return value of any function either in a variable, or as
>> part of another function call.
>>
>> For instance, to return the position in a string where the first space
>> appears in a variable you might have:
>> ;--
>> Var
>> String address,
>> Int position
>> let address = "58 tarrigal road,"
>> let position = stringContains(address," ")
>> ;--
>> The variable Position now holds the number 3 - because in "58 tarrigal
>> road," the first space is the third character (the 5 being the first, 8
>> the
>> second, and so on).
>> By using this variable approach you can check if your position is 0
>> (indicating no spaces) and act accordingly.
>>
>> How would you insert a comma before this space, then? Something like:
>> ;--
>> Let address = stringLeft(address,position -1) +",
>> "+StringChopLeft(address,position)
>> ;--
>> And address now equals "58, tarrigal road,"
>> To explain this code:
>> The first function we call, stringLeft, returns any leftmost number of
>> characters from a string.   We want the number, in this case.  Our
>> position
>> includes the space, so we want the leftmost characters up to but not
>> including the space - so we use "position -1" to tell the script that.
>> The stringChopLeft function takes away any leftmost characters and 
>> returns
>> whatever's left, so after we've added our comma, we chop off everything 
>> up
>> to and including our space, and tack it back on to the end of our address
>> which now includes a comma.
>>
>>
>> As you can see from the above example, we've used the returning strings
>> from
>> the functions as well as our counter variable. Suppose you wanted to put
>> the
>> number of the address into a variable without having to keep a position?
>> You could call the stringContains function as part of the stringLeft
>> function.  The second parameter to stringLeft is the number of characters
>> to
>> return, and stringContains returns the position of a character, so your
>> code
>> might look like:
>> ;--
>> Var
>> String addressNumber
>> Let addressNumber = stringLeft(address,stringContains(address," ")-1)
>> ;--
>> Remembering we add the -1 because we don't want the space.
>>
>> If the layout of what to put where confuses you, you might want to think
>> about using the "insert function" button in the parameter box of the
>> insert
>> function dialog box.
>>
>> I.e.
>> 1. press ctrl+I for insert function, and choose stringLeft.
>> 2. For parameter 1, type address.
>> 3. For parameter 2 ("The number of leftmost characters that will be
>> extracted."), click Insert Function and choose "stringContains".
>> 4. For parameter 1 here, provide "address"
>> 5. For parameter 2, you want a space in quotes " ".
>> 6. You're returned to your stringLeft function with code already present
>> and
>> can add your -1 to the end before hitting enter to insert the code.
>>
>> So hopefully you see that's how you use a return value of the function
>> inside another function.  It's just a matter of using data in exactly the
>> same way as usual, but rather than storing the information in a variable
>> or
>> passing it directly to your function as a string, you're generating the
>> information on-the-fly from other functions.
>>
>> This can really build up and you have to watch your nesting of brackets,
>> quotation marks and commas - just remember that all functions need open
>> and
>> closing parentheses and that each parameter must be separated by a comma.
>>
>> Righty ho - must dash, early morning start and I'm off into the sunshine
>> to
>> do some voluntary computer work.  I hope this made vague sense - if you
>> can
>> grasp this one then you're well on your way!
>> All code untested, and I'm hardly awake - so good luck.
>>
>> Sean.
>> "Never interrupt your enemy when he is making a mistake." Napoleon
>> Bonaparte
>> -----Original Message-----
>> From: jawsscripts-bounce@xxxxxxxxxxxxx
>> [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Geoff personal
>> Sent: Monday, April 06, 2009 7:26 AM
>> To: jawsscripts@xxxxxxxxxxxxx
>> Subject: [jawsscripts] inserting a comma after first word in a string?
>>
>>
>> Hey Firstly Mr Paul Magill from Aus,, and Mr Don ,
>>
>> man I sure owe you guys a lot! and a reply and acknowledgement for the
>> last
>> incredibly detailed and helpful post you sent on my \9 tab splitting up
>> info.
>> absolutely fabulous that was! Thank you for that eh.
>>
>> the reason I haven't replied yet, is that I got busy with other parts of
>> the
>>
>> code, and to be honest haven't yet had/made time to really sit down and
>> get
>> down and dirty with either yours or don's last great examples.
>>
>> But, I will, for at the moment my GetLine functions, which are the only
>> ones, as you seemed to confirm, that will retain Tabs in order to do the
>> delineation
>> for inserting pauses, is doing it ok, but I haven't put in intelligent
>> enough stuff to stop getting lines when the next line text isn't the
>> CornFlowerBlue
>> on black color. which I must work out how to do properly before that will
>> be
>>
>> a seemless function.
>>
>> But I'm incredibly greatful for the \n and \9 ideas, that backSlash n is
>> proving absolutely invaluable for my HotKey help stuff I'm wanting to
>> formulate
>> right now into virtual viewer.  I never knew about those gems before!
>>
>> Now On to today's sinario though if I might.
>>
>> I've got a couple of issues I'm desirous of, ... yep just a little more
>>
>> assistance with, <sigh,>  regarding what can be done with strings, as
>> against doing things directly OnScreen?
>>
>> 1. I have a situation where I need to try and insert a comma between a
>> street Number and streetName, in a string picked up in a GetTextInRect
>> string,  to
>> assist firstPass immediate comprehension by the user,of situations like
>> the
>> following addresses:
>>
>> 50A warrigal road,
>>
>> 58 tarrigal road,
>>
>> 45C seaforth avenue,
>>
>> such that they speak like:
>>
>> 50A, Warrigal road,
>>
>> 58, terrigal road,
>>
>> 45C, seaforth avenue,
>>
>> etc.
>>
>> I'm wondering what people think might be the bestest way to do this?
>>
>> e.g. these often appear in a whole table-like matrix, so I've grabbed all
>> the strings with GetTextInRects, so I don't really at all wanna have to 
>> do
>> direct
>> Onscreen things like mess with Cursors, like SaveCursor, InvisibleCursor,
>>
>> go to certain point on the screen, GetWord, addItToString, +","
>> add a comma,
>> NextWord () GetWord (), add that to string, ... etc.
>>
>> That'd be just sooooo horribly messy and inelegant!
>>
>> Especially given that I'm calling this via an OnFocus frame event, which
>> triggers the script to check the FrameName at Cursor, and if it's x, go 
>> to
>> Y
>>
>> rectangle
>> and grab and speak text in there etc, and I think the above way would
>> prove
>> waay to slow surely, to be useable?
>>
>> Plus I'm not even sure I'd know how to reliably build my String that way
>> anywayz! So, I'm wanting to know, how one could move to certain points in
>> a
>> pregatehred string
>> like that?
>>
>> Like I'm pretty horribly green in script land, so this'll be painfully
>> obvious to you pros out there,
>> but, well like Although I've been Told that the
>>
>> "StringContains"
>>
>> funcion, somehow, returns, the first position of the beginning character,
>> of the string being looked for,
>> Such that I half dimly thought I might be able to do something like,
>>
>> if StringContains (MyStringToLookIn, "\0") then
>>
>> ; i.e. I'm asking it if my string has any spaces in it,
>>
>> How exactly might I utilize any ability of this function, to perhaps stop
>> at
>>
>> the first space it sees, possibly enabling me to somehow then extract how
>> many
>> characters in from the left that was? In order to insert my comma?
>>
>> or how else do people think  I might exactly code this up such that I
>> could
>> then insert a comma at that point,
>> in, "MyStringToLookIn," variable?
>>
>> And then put the whole thing back together such that it inserted the 
>> pause
>> at the right spot?
>>
>> Like really, I reckon I still just soooo don't get this idea of how to
>> utilize what a function, "Returns",
>> and subsequently utilizing those as fodda/data for other functions to 
>> work
>> on?
>>
>> I'ts logic I just haven't gotten my head properly around yet.
>>
>> Like I can sorta use functions, like straight, but I don't really yet get
>> how one begins to use, the data any given function, "returns," in any 
>> kind
>> of
>> useful way in another function I don't think.
>>
>> Like I believe I mostly understand the, If then ElIf, else, Endif cycle,
>> But this utilizing returns from other functions business, and how to make
>> another function readily be able to accept such data, presumably by their
>> parameters
>> at the top, ... that's kind of all a closed book to me at present.
>>
>> Like I dimly thought that if I knew how many characters to the right, the
>> first space was, I could maybe somehow then do a StringChopLeft type 
>> deal,
>> for
>> which you've seemingly gotta specify a character count,
>> which I thought then might've allowed me to save that chopped off 
>> section,
>> hopefully my streetNumber word as the first Word of the string, (which of
>> course I guess
>> might actually end up being two numbers separated by a slash as well just
>> to
>>
>> make things more complicated,
>> as in apartments like 12/106 xx ?Street, blah.
>> into a temporary variable,
>> then Save the chopped string into another temporary variable,
>> then do a string concatination with a comma in the mniddle of the two 
>> etc.
>>
>> could that be done though? would it work? would there be some easier way?
>>
>> it all sounds a rather hotchPotch method though?
>>
>> But, would anyone care to suggest anything or provide me with any
>> exemplery
>> code as to how I might get around this one?
>> Like I mean can one do, NextWord type functions on Strings, like you can
>> OnScreen?
>>
>> I was sure one would have to be able to utilize them as flexibly as the
>> OnScreen stuff, but, ... well my knowledge of the String functions is at
>> present
>> just too limited to work out exactly how I might do it?
>>
>> Thanks heaps for any help on this one. I think I'll do these situations
>> one
>> post at a time, it'll be simpler for replies.
>>
>> Thanks again.
>>
>> Geoff Chapman.
>>
>> __________
>> 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: