ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: transform(d|t, 'format')   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

jeu. 07 juin 2012, 17h07
Gregory
atoutfox.public.association

Re: transform(d|t, 'format')

> * Il ne faut pas remplacer ce qui a été substitué exemple JJJJ ->
> "Jeudi" -> 7eudi


Cette fois-ci, Francis, tu peux utiliser, une regex, tu as ta collection de
matches que tu traites le dernier match d'abord

pattern : J+|M+|A+|D+|M+|Y+
global = true
ignorecase = false


for I = matches.Count - 1 to 0 step -1
&& remplacement
endfor




______
Gregory
______
"Francis Faure" wrote in message news:jqqfe1$86$1@news.niouzes.net...

Autre proposition :

clear
SET DATE FRENCH
SET CENTURY on
? DtoCx()
? DtoCx(DATE(), "JJ/MM/AAAA")
? DtoCx(DATE(), "J/M/AA")
? DtoCx(DATE(), "JJJ, J MMM-AAAA")
? DtoCx(DATE(), "Le JJJJ, J MMMM AAAA")
? DtoCx(DATE(), "D-M-Y, DD/MM/YY, DDD DD-MMM-YYY, DDDD D MMMM AAAA")

* Retourner une chaine contenant une date formatée selon masque de type
Excel
* AAAA / YYYY = Année avec siècle
* AAAA / YYYY = AAAA
* AA / YY = Année sans le siècle
* A / Y = Année 1 chiffre
* M  = n° du mois court
* MM  = n° mois sur 2 chiffres
* MMM = 3 Premiere lettres du Nom du Mois
* MMMM = Nom du Mois
* J / D= n° du jour court
* JJ / DD = n° jour sur 2 chiffres
* JJJ / DDD = 3 Premiere lettres du Nom du Jour
* JJJJ / DDD = Nom du Jour
FUNCTION DtoCx(ldDate, lsFormatExcel)
  IF TYPE("m.ldDate")<>"D"
    ldDate=DATE()
  ENDIF
  IF TYPE("m.lsFormatExcel")<>"C"
    lsFormatExcel="JJ/MM/AAAA"
  endif
  LOCAL lsAAAA as String, lsAAA as String, lsAA as String, lsA as String
  LOCAL lsMMMM as String, lsMMM as String, lsMM as String, lsM as String
  LOCAL lsJJJJ as String, lsJJJ as String, lsJJ as String, lsJ as String
  lsJJJJ = PROPER(CDOW(m.ldDate))
  lsJJJ  = LEFT(m.lsJJJJ,3)
  lsJJ   = PADL(DAY(m.ldDate),2,"0")
  lsJ    = ALLTRIM(STR(DAY(m.ldDate),2,0))
  lsMMMM = PROPER(CMONTH(m.ldDate))
  lsMMM  = LEFT(m.lsMMMM,3)
  lsMM   = PADL(MONTH(m.ldDate),2,"0")
  lsM    = ALLTRIM(STR(MONTH(m.ldDate),2,0))
  lsAAAA = STR(YEAR(m.ldDate),4,0)
  lsAAA  = m.lsAAAA
  lsAA   = right(m.lsAAAA, 2)
  lsA    = right(m.lsAAAA, 1)
  * Il ne faut pas remplacer ce qui a été substitué exemple JJJJ ->
"Jeudi" -> 7eudi
  * et format possible anglais. Passage par <9999> Année <8888> Mois <7777>
Jours ...H M S a faire
  * (l'ordre STRAN a une importance : plus long au plus cours)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "AAAA", "<9999>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "AAA", "<999>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "AA", "<99>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "A", "<9>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "YYYY", "<9999>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "YYY", "<999>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "YY", "<99>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "Y", "<9>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "MMMM", "<8888>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "MMM", "<888>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "MM", "<88>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "M", "<8>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "JJJJ", "<7777>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "JJJ", "<777>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "JJ", "<77>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "J", "<7>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "DDDD", "<7777>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "DDD", "<777>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "DD", "<77>", 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "D", "<7>", 1)
  * -
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<9999>", m.lsAAAA, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<999>", m.lsAAA, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<99>", m.lsAA, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<9>", m.lsA, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<8888>", m.lsMMMM, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<888>", m.lsMMM, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<88>", m.lsMM, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<8>", m.lsM, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<7777>", m.lsJJJJ, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<777>", m.lsJJJ, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<77>", m.lsJJ, 1)
  lsFormatExcel=STRTRAN(m.lsFormatExcel, "<7>", m.lsJ, 1)
  RETURN m.lsFormatExcel
ENDFUNC

Permalink : http://www.atoutfox.org/nntp.asp?ID=0000009139
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3