Bonjour,
J'ai besoin de recuperer le contenu entier d'un fichier texte unicode dans une variable 4D, comment puis-je faire? Quelqu'un peut m'aider svp?
Bonjour,
J'ai besoin de recuperer le contenu entier d'un fichier texte unicode dans une variable 4D, comment puis-je faire? Quelqu'un peut m'aider svp?
Bonjour,
Tu as :
- le code de Vincent de Lachaux "Encoder et décoder du texte" qui utilise les commandes XML.
- et si le texte est spécialement en UTF8, tu as un code sur le site de Solutions 4D, que je copie ci-dessous. Tu trouveras ce code (UTF8 vers texte) et son code inverse (texte vers UTF8) en allant dans la rubrique Base de connaissances et en entrant "utf8" dans le champ de recherche par titre.
Conversion UTF8 vers Texte
par Bruno LEGAY @ AC Consulting
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 `Méthode projet: TXT_UTF8_2_Text ` Méthode publique ` `DESCRIPTION : ` Cette fonction converti des caractère UTF-8 en ISO 8559-1 ` `PARAMETRES : ` $0 (TEXTE) <= Texte converti ` $1 (TEXTE) => Texte en UTF-8 ` $2 (BOOLEEN) => Convertir le texte en jeux Macintosh (Optionel, défaut Vrai), ` sinon le jeux de caractères est ISO 8559 ` `NOTE : ` `EXAMPLE D'APPEL : ` `CREATION : Bruno L. - 29/07/2002 11:51:17 - v1.16.00 ` création ` ` 1999-2001 © A&C Consulting `*=============================================================================== C_TEXTE($0) `Text in ISO 8559-1 C_TEXTE($1) `Text in UTF-8 C_BOOLEEN($2) `Convert in Mac charset (Optional, default True), in ISO 8559-1 otherwise C_TEXTE($vt_Converted_Text) `Text in ISO 8559-1 ou Mac C_TEXTE($vt_Texte_UTF8) `Text in UTF-8 C_BOOLEEN($vb_ConvertIntoMacCharSet) C_ENTIER LONG($vl_Ascii;$i;$vl_Iso;$vl_UTF8_Length;$vl_Counter;$vl_NbParam) C_ALPHA(1;$va_Char_UTF8;$va_Char_Iso) $vt_Converted_Text:="" $vl_NbParam:=Nombre de parametres Si ($vl_NbParam>0) $vt_Texte_UTF8:=$1 Au cas ou : ($vl_NbParam=1) $vb_ConvertIntoMacCharSet:=Vrai Sinon $vb_ConvertIntoMacCharSet:=$2 Fin de cas $vl_UTF8_Length:=Longueur($vt_Texte_UTF8) Si ($vl_UTF8_Length>0) $vt_Converted_Text:=MAXLARGTEXTE *Caractere(ASCII SP ) $vl_Counter:=0 Boucle ($i;1;$vl_UTF8_Length) $va_Char_UTF8:=$vt_Texte_UTF8[[$i]] $vl_Ascii:=Code ascii($va_Char_UTF8) Au cas ou : (Non($vl_Ascii ?? 7)) `Most common scenario, the 8th high bit is set `to 0, it is a 7 bit ascii... $va_Char_Iso:=$va_Char_UTF8 : (Non($vl_Ascii ?? 6)) `The seventh bit is set to 0 so we have 100xxxxx `This is impossible in UTF-8 if the 8th bit was not set $va_Char_Iso:="?" : (Non($vl_Ascii ?? 5)) `The sixth bit is set to 0 so we have 110xxxxx $i:=$i+1 `2 byte encoded char `In theory we should use this but since 4D can only hack 0-255 characters, we do `we don't bother with the bit stored in the 5 remaing bits of the first byte `$va_Char_Iso:=((($vl_Ascii & 0x001F) << 8)+$vt_Texte_UTF8[[$i]]) & 0x00FF `To be confirmed... `$va_Char_Iso:=$vt_Texte_UTF8[[$i]] $va_Char_Iso:=Caractere((($vl_Ascii ^| 0x00C0) << 6)+(Code ascii($vt_Texte_UTF8[[$i]]) & 0x003F)) : (Non($vl_Ascii ?? 4)) `The fifth bit is set to 0 so we have 1110xxxx $i:=$i+2 `3 byte encoded char $va_Char_Iso:="?" : (Non($vl_Ascii ?? 3)) `The fourth bit is set to 0 so we have 11110xxx $i:=$i+3 `4 byte encoded char $va_Char_Iso:="?" : (Non($vl_Ascii ?? 2)) `The third bit is set to 0 so we have 111110xx $i:=$i+4 `5 byte encoded char $va_Char_Iso:="?" : (Non($vl_Ascii ?? 1)) `The second bit is set to 0 so we have 1111110x $i:=$i+5 `6 byte encoded char $va_Char_Iso:="?" Fin de cas $vl_Counter:=$vl_Counter+1 $vt_Converted_Text[[$vl_Counter]]:=$va_Char_Iso Fin de boucle $vt_Converted_Text:=Sous chaine($vt_Converted_Text;1;$vl_Counter) Si ($vb_ConvertIntoMacCharSet) $vt_Converted_Text:=ISO vers Mac($vt_Converted_Text) Fin de si Fin de si Fin de si $0:=$vt_Converted_Text
Merci, je viens juste de voir ta réponse.
j'avais trouvé une autre solution, mais tellement bricolé (je prend un caractere sur 2) que je vais prendre la tienne.
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager