Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Chrtran() applied selectively
Message
De
07/06/2016 06:04:41
 
 
À
07/06/2016 02:58:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01636985
Message ID:
01637049
Vues:
58
>>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
>
>Hi Karen:
>
>Another solution here :D
>
>Considering that there are always three "parts" separated by ":" symbol, this will do it in pure VFP:
>
>
>mstr='1st-title: ANAME-HER : 3520931 place[21-22]'
>? GETWORDNUM(mstr, 1, ':') + ':' + GETWORDNUM(mstr, 2, ':') + ':' + CHRTRAN(GETWORDNUM(mstr, 3, ':'), '-', '.')
>
Having to consider nothing more than the original (and even subsequent) Karen's requirements, in"pure" VFP this would do:
m.mstr = "1st-title: ANAME-HER : 3520931 place[21-22]"

? LEFT(m.mstr,RAT("[",m.mstr)) + CHRTRAN(SUBSTR(m.mstr,RAT("[",m.mstr)+1)," +=-~",".....")
The rationale for the use of regular expressions, though, is that it widens the coverage of variations handling without having to change code, just pattern data. For instance,
? PATTERNTRAN("1st-title: [1-2] ANAME-HER:HIS : 3520931 place[ 21 ~ 22]  ", "\[\s*(\d+)[^\d]+(\d+)\s*\]\s*$","[$1.$2]")
would cover other variations and introduce a boost in data normalization (that's what Karen is looking for).
----------------------------------
António Tavares Lopes
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform