Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Chrtran() applied selectively
Message
De
04/06/2016 03:37:10
 
 
À
04/06/2016 03:35:35
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01636985
Message ID:
01636992
Vues:
70
>>>>>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
>>>>*_______________________________________________________________________________
>>>>
>>>
>>>This is a great demonstration that the _regexpr FFC is deserving a boost.
>>
>>Hey Antonio,
>>
>>I've never used FFC
>>
>>Regex has a leaning curve, and I like regex a lot
>
>Yes, it's also a great fun to use.
>
>The boost I was referring to is to simply expose the other methods & properties of the underlying VBScript engine, such as Replace.

I see
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform