[jawsscripts] Re: String Segment Count

  • From: "Mike" <mike_sharp@xxxxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Tue, 6 Jul 2010 12:34:00 +0100

Martin,

Thanks very much for looking at the script and for your reply.
The double space in the string is a mistake, sorry about that.
The result you had is sort of what I am looking for but could you just 
explain the delimiters you used.

In my script I have:
Let iStart = 1 Let iFinish = StringSegmentCount (sData, " -") + 1
and also:
Let sText = StringSegment (sData, " ", iStart)
When you say both StringSegments need to have the same delimiters I gather 
from that I need to add the hyphen to the second string segment statement?

The returned string you have is better than what I was getting, however, I 
need the hyphen to remain when reconstrcuting the string, could you suggest 
a way in which that could be done?

Also, stupidly on my part, it's all very well it working in the way I have 
it setup but it is pretty unlikely that a person is going to be called 
McMike McJones (unless their parents were having a laugh!). When I try my 
function with a string MIKE MCJONES I don't get the full name returned.

I have added an else statement to the If statement but the string is missing 
some segments, only the first segements that do not begin with MC are 
returned.

So far the revised script looks like this:
Var
String sData, String sData2, String sData3, String sData4, String sData5, 
String sText,
Int iStart, Int iFinish, Int iLength

Let sData = "MIKE JOHN MCBAIN"
Let iStart = 1 Let iFinish = StringSegmentCount (sData, " -") + 1
While iStart < iFinish
Let sText = StringSegment (sData, " -", iStart)
Let iLength = StringLength (sText)
Let sData2 = SubString (sText, 1, 2)
If sData2 == "MC" Then
    Let sData2 = StringUpper (StringLeft (sData2, 1)) + StringLower 
(Substring (sData2, 2, StringLength (sData2)))
    Let sData3 = StringChopLeft (StringLeft (sText, iLength), 2)
    Let sData3 = StringUpper (StringLeft (sData3, 1)) + StringLower 
(Substring (sData3, 2, StringLength (sData3)))
    Let sData4 = (sData2 + sData3) Else
    Let sData4 = StringUpper (StringLeft (sText, 1)) + StringLower 
(Substring (sText, 2, StringLength (sText)))
    If iStart == iFinish Then
        Let sData5 = sData5 + sData4 Else
        Let sData5 = sData5 + sData4 +" "
    EndIf
EndIf
Let iStart = iStart + 1
EndWhile
Copytoclipboard (sData5)
Return (sData5)


Regards

Mike

--------------------------------------------------
From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
Sent: Tuesday, July 06, 2010 9:51 AM
To: <jawsscripts@xxxxxxxxxxxxx>
Subject: [jawsscripts] Re: String Segment Count

> Mike,
>
>  One thing I noticed was that your test string had two adjacent spaces
> between two of the names, so one of the segments you were testing would 
> have
> been null.  The other thing to bear in mind is to give ALL your
> StringSegment functions the same set of delimiters.  When I did this, your
> code produced the output:
>
> McDave1 McDave2 McDave3 McDave4 McDave5 McDave6
>
>  Is this what you are looking for?  I'm still not sure how you want to
> handle double-barrelled names.
>
>  Martin
>
>
> ----- Original Message ----- 
> From: "Mike" <mike_sharp@xxxxxxxxxxxxx>
> To: <jawsscripts@xxxxxxxxxxxxx>
> Sent: Tuesday, July 06, 2010 8:39 AM
> Subject: [jawsscripts] Re: String Segment Count
>
>
> Geoff and all.
>
> I tried as suggested and it did not work. Let me explain what I am trying 
> to
> achieve and paste the code thus far.
> I am capturing names from a screen which need to be formatted in the 
> correct
> way. This particular function has to check for names beginning with Mc and
> format it in such a way that the name appears like McTavish. My script 
> works
> where the string has a blank space between each forename or surname but in
> some cases the name may be hyphenated. I need the string segment count to
> look for a blank space and a hyphen. Here is my working code so far, maybe
> someone can critique what I have done and suggest a way forward.
> As always..thanks in advance for the help.
>
> Var
> String sData,
> String sData2,
> String sData3,
> String sData4,
> String sData5,
> String sText,
> Int iStart,
> Int iFinish,
> Int iLength
>
> Let sData = "MCDAVE1  MCDAVE2-MCDAVE3 MCDAVE4 MCDAVE5 MCDAVE6"
> Let iStart = 1 Let iFinish = StringSegmentCount (sData, " -") + 1
> While iStart < iFinish
> Let sText = StringSegment (sData, " ", iStart)
> Let iLength = StringLength (sText)
> Let sData2 = SubString (sText, 1, 2)
> If sData2 == "MC" Then
> Let sData2 = StringUpper (StringLeft (sData2, 1)) + StringLower (Substring
> (sData2, 2, StringLength (sData2)))
> Let sData3 = StringChopLeft (StringLeft (sText, iLength), 2)
> Let sData3 = StringUpper (StringLeft (sData3, 1)) + StringLower (Substring
> (sData3, 2, StringLength (sData3)))
> Let sData4 = (sData2 + sData3)
> If iStart == iFinish Then
> Let sData5 = sData5 + sData4 Else
> Let sData5 = sData5 + sData4 +" "
> EndIf
> EndIf
> Let iStart = iStart + 1
> EndWhile
> Copytoclipboard (sData5)
> --------------------------------------------------
> From: "Geoff Chapman" <gch@xxxxxxxxxxxxxxxx>
> Sent: Tuesday, July 06, 2010 5:12 AM
> To: <jawsscripts@xxxxxxxxxxxxx>
> Subject: [jawsscripts] Re: String Segment Count
>
>> Hi Mike.
>> well, I stand to be corrected, but my understanding was that you just
>> shoved
>> all of them next to each other inside quotation marks as the second param
>> of
>> the function?
>> i.e.
>>
>> StringSegmentCount (MyString, "| ")
>>
>>
>> the multiple delimiters in this case would be vertical bar followed by a
>> space, in sequence.
>> thus a vertical bar with no space following it, would not be considered
>> legal for the above code?
>>
>> BTW, you can also use, as can be very handy in some situations, and end 
>> of
>> line character of "\n" as a delimiter as well.
>>
>> hth..
>> ----- Original Message ----- 
>> From: "Mike" <mike_sharp@xxxxxxxxxxxxx>
>> To: <jawsscripts@xxxxxxxxxxxxx>
>> Sent: Tuesday, July 06, 2010 9:10 AM
>> Subject: [jawsscripts] String Segment Count
>>
>>
>>> Hi All,
>>>
>>> I am a bit unsure on how to specify more the one delimiter in the
>>> stringsegmentcount function, can someone let me know how it is done?
>>>
>>> Regards,
>>>
>>> Mike
>>>
>>> __________�
>>>
>>> View the list's information and change your settings at
>>> http://www.freelists.org/list/jawsscripts
>>>
>>
>> __________�
>>
>> View the list's information and change your settings at
>> http://www.freelists.org/list/jawsscripts
>>
>>
> __________�
>
> View the list's information and change your settings at
> http://www.freelists.org/list/jawsscripts
>
> __________�
>
> View the list's information and change your settings at
> http://www.freelists.org/list/jawsscripts
>
> 
__________�

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

Other related posts: