Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Chrtran() applied selectively
Message
 
À
05/06/2016 07:27:40
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01636985
Message ID:
01637039
Vues:
55
actually your solution greg does well but does not replace a space with a dot whereas Antonio's solution does.

s ='1st-title: ANAME-HER : 3520931 place[4443 4444]' &&&XXX

using Antonio's middle parameter replaces space with dot - so perhaps combining the two.
regexObj.Pattern = '(\[\d{1,4}).(\d{1,4}\])'
>I see Antonio answered
>
>It's basically expanding the second part between parentheses
>
>Also, if the number of digits can be different, say from one to 4
>
>
>
>function do_it()
>	
>	local regexObj
>	regexObj = createobject('VBScript.RegExp')
>	regexObj.Global = .t.
>	regexObj.IgnoreCase = .f.
>	regexObj.Pattern = '(\[\d{1,4})([\x21-\x2f\x7b-\x7f])(\d{1,4}\])'
>	
>	local s, x
>	s ='1st-title: ANAME-HER : 3520931 place[1~4444]'
>	?s
>	x = m.regexObj.Replace(m.s, '$1.$3')
>	?x
>	
>endfunc
>*_______________________________________________________________________________
>
>
>>many thanks for all the suggestions. I will spend the day today trying the solutions out and see how far I get.
>>
>>greg - is there a way in your pattern to keep the hyphen (-) open to any character - it could end up being :~+= (I never what what's coming down the pipe - I anticipate most of the time the error will be in the form of a hyphen that I need to convert back to a dot. Perhaps an asc that covers all chr from 1-49 before the numbers start. so asc(1..49) in lieu of (-) I don't know how that would be represented in code or if it is even possible.
>>regexObj.Pattern = '(\[\d\d)(-)(\d\d\])'
>>
>>thanks
>>k
>>
>>>>I am searching for the most expedient way to change a character in a specific area of a string.
>>>>
>>>>mstr='1st-title: ANAME-HER : 3520931 place[21-22]'
>>>>in this string the hyphen between 21 and 22 should be a dot.
>>>>if I applied chrtran() I would end up changing all the hyphens which I do not want to do.
>>>>
>>>>right now all I've been able to accomplish is to locate the error in a portion of the string, but putting it back together is starting to get a bit unwieldy.
>>>>Is there a simpler more direct route of directing the chrtran() to the area beyond '['
>>>>
>>>>thanks
>>>>k
>>>Karen,
>>>
>>>If you have been able to locate the error portion, use something like
>>>
>>> substr(mstr,1 , pos-1) + '.' + substr(mstr, pos+1)
>>>
>>>
>>>Also, if
>>>(1) [ followed by two digits are immediately before the hyphen, and
>>>(2) two digits and ] immediately follow the hyphen
>>>
>>>Then regular expressions may be of help
>>>
>>>
>>>*_______________________________________________________________________________
>>>function do_it()
>>>	
>>>	local regexObj
>>>	regexObj = createobject('VBScript.RegExp')
>>>	regexObj.Global = .t.
>>>	regexObj.IgnoreCase = .f.
>>>	regexObj.Pattern = '(\[\d\d)(-)(\d\d\])'
>>>	
>>>	local s, x
>>>	s ='1st-title: ANAME-HER : 3520931 place[21-22]'
>>>	?s
>>>	x = m.regexObj.Replace(m.s, '$1.$3')
>>>	?x
>>>	
>>>endfunc
>>>*_______________________________________________________________________________
>>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform