< Translinguisme

Types et valeurs

Types

LangagesTypes de variable supportés
Cchar, double, enum, float, int, long, short, signed, struct, union, unsigned, void
Javaboolean, char, byte, short, int, long, float, double, void

Boolean, Character, Byte, Short, Integer, Long, Float, Double, Void, Object, String, Enum, Date, File, Class, Method, ...

LibO Basicboolean, currency, date, double, float, integer, long, single, string
Pythonbasestring, bool, complex, dict, exception, file, float, fonction, frozenset, int, list, long, module, none, NotImplementedType, object, set, slice, str unicode, tuple, type, xrange[1]
SQLbigint, bit varying, char, date, datetime, decimal, double precision, float, integer, numeric, real, smallint, time, varchar, year[2]
VBByte, Boolean, Integer, Long, Single, Double, String[3]
PHPNULL, boolean, integer, float, string, array, object
HTMLtext, file, radio, checkbox, submit, hidden

Valeurs

LangageRéférence/ pointeur nulTest nulChaîne de caractère
Caractère
EntierFlottantBooléenAllocation/libération mémoire
Ada"Un exemple accentué à moins de 1."
'E'
512 0x200 -1233.14 314.159E-2False Trueallocation :
libération :
C(void*)0"Un exemple accentué à moins de 1\x80."
'E'
512 0x200 -1233.14 314.159E-20 1allocation : ptr = malloc(size)
libération : free(ptr)
JavanullisEmpty()"Un exemple accentué à moins de 1\u20AC."
'E'
512 0x200 -1233.14 3.14D 314.159E-2false trueallocation : ref = new class(arguments...)
libération : ref = null; /* garbage collector */
JavaScriptnulltypeof X != 'undefined'"Un exemple accentué à moins de 1\u20AC."
'E'
512 0x200 -1233.14 314.159E-2false trueallocation : ref = new prototype_constructor_function(arguments...)
libération : ref = null; /* garbage collector */
Pascalnil'Un exemple accentué à moins de 1.'
'E'
512 $200 -1233.14 314.159E-2False Trueallocation :
libération :
PHPnullis_null()
isset()
function_exists()
False True
Pythonnullis None"Un exemple accentué à moins de 1\u20AC."
'E'
512 0x200 -1233.14 3.14 314.159E-2False True
VBAnullisEmpty()False True
SQLNULLMySQL : isnull(), ifnull()
MSSQL : isnull()
False True

Syntaxes de base

Structure du code

LangageBloc d'instructionsCondition simpleCondition à cas multiplesBouclesSous-programmesModuleProgramme principalCapture d'exception
Windows PowerShell (DOS)(
...
)
if ...condition... ...commande... else ...commande...for %%var in ( liste_ou_file_pattern ) do ...call :nom ...
...
:nom
...
goto :eof
séquence des commandes du fichier
Shell Unixif
...
fi
séquence des commandes du fichier
Pythonindentationif ... :
...
elif ... :
...
else:
while ... :
for ... :
Déclaration :
implicite par la hiérarchie des répertoire
utilisation :
import module;
from module import names;
try:
...
except ... :
...
Adabegin
...
end;
if (...) then ...
elsif (...) then ...
...
else ...
end if;
case (...)
when ... => ...
when others => ...
end case;
while (...) loop
...
end loop;
function nom(parametre:type;...) return type is
...
begin
...
return ...;
end;

procedure nom(parametre:(in/out/in out) type;...) is
...
begin
...
end;
nom.ads (spécification) :
package nom is
...
end nom;
nom.adb (corps) :
package body nom is
...
end nom;
utilisation :
with package,...; -- déclarer
use package,...; -- utiliser l'espace de nom
procedure nom is
...
begin
...
end;
Pascalbegin
...
end;
if ... then ...
else if ... then ...
...
else ...
case ... of
... : ...
else ...
end;
while ... do ...

repeat
...
until ...;


for var := start to end do ...
for var := start downto end do ...
function nom(parametre:type;...) : type;
...
begin
...
nom := ...;
end;

procedure nom(parametre:type;...);
...
begin
...
end;
unit nom;
interface
...
implementation
...
end.
utilisation :
uses unité,...;
program nom;
...
end.
C{
...
}
if (...) ...
else if (...) ...
...
else ...
switch(...)
{
case ...:...
...
default:...
}
while (...) ...
do ... while (...);
for (...;...;...) ...
type_retour nom(type param,...){...}utilisation :
#include fichier
int main(int argc, char** argv)
{ ... }
C++{
...
}
if (...) ...
else if (...) ...
...
else ...
switch(...)
{
case ...:...
...
default:...
}
while (...) ...
do ... while (...);
for (...;...;...) ...
type_retour nom(type param,...){...}utilisation :
#include fichier
using namespace namespace;
int main(int argc, char** argv)
{ ... }
try { ... }
catch(type var) { ... }
PHP{
...
}
try { ... }
catch { ... }
Java{
...
}
if (...) ...
else if (...) ...
...
else ...
switch(...)
{
case ...:...
...
default:...
}
while (...) ...
do ... while (...);
for (...;...;...) ...
type_retour nom(type param,...){...}Déclaration (1ère ligne) :
package package;
utilisation :
import package.(classe ou *);
public static void main(String[] args)
{ ... }
try { ... }
catch(type var) { ... }
finally { ... }
JavaScript{
...
}
if (...) ...
else if (...) ...
...
else ...
switch(...)
{
case ...:...
...
default:...
}
while (...) ...
do ... while (...);
for (...;...;...) ...
function nom(param,...){...}séquence des commandes du fichiertry { ... }
catch(var) { ... }
Visual Basicrienif ... then
...
elseif ... then
...
end if
while ... wend
do while ... loop
for ... next
callon error resume next
...
on error goto 0
LibO Basicrienif ... then
...
elseif ... then
...
end if
while ... wend
do while ... loop
for ... next

Commentaires et commandes de bases

LangageLigne de commentaireBloc de commentaireÉcha-
ppement
AfficherSaisirDéclarationDéfinitionÉgalDifférentEtOu
Windows PowerShell (DOS)rem<# ... #>^echopause, SET /P variable=[promptString], choix multiple : choice, copie : copy convariable : set, fichier : cp, copy, xcopy= (on appelle ensuite les variables avec %variable%)==, EQU!==!, NEQ-and[4]-or
Shell Unix#: <<'END'...END\echosleep, readfichier : touch, cp, mv==!=&&||
Python#'''...''', """..."""\printraw_input()riendef==!=andor
Ada--rien\Put(), Put_Line()Get(), GetLine()variable:type:==/=andor
Pascalrien{...} ou (*...*)Chr()Write(), Writeln()Read(), Readln()var variable:type:==<>andor
Crien/*...*/\printf(), fprintf(), sprintf(), puts()scanf()voir le paragraphe types=, adresse de pointeurs : ====!=&&||
C++///*...*/\cout<<cin>>voir le paragraphe types=, adresse de pointeurs : ====!=&&||
PHP//, ou #/*...*/\echo, printf$_GET, $_POSTObjet : new=, variable : $==!&&||
Java///*...*/\System.out.println()BufferedReader.readline(), JTextArea,JTextField.getText(), JOptionPane.showInputDialog()voir le paragraphe types, Objet : new===, objet : .equals()!=&&||
JavaScript///*...*/\alert()prompt()var===!=&&||
HTML<!--...--><!--...-->&rien<input>rien=rienrienrienrien
SQL--,
Oracle : rem, @[5]
/*...*/"selectprinttable : create tablevariable : :, table : update, insert=notandor
Visual Basic', remrien"MsgBoxInputBoxvariable : dim
fonction : sub
=, fichier : .CopyFile
fichier, feuille : .new
=<>andor
LibO Basic', remrien"MsgBoxInputBoxvariable : dim
fonction : sub
==<>and[6]or

Syntaxe et traitement de chaînes

LangageRetour à la ligneConcaténationWildcardClasserLongueurMajusculeMinusculeRechercher dans une chaîneRechercher remplacerTronquer une chaîneRogner
Windows PowerShell (DOS)\r\ncommandes traitant le résultat de la précédente : |*sort /r
Shell Unix\ncommandes : &&, ;, commandes traitant le résultat de la précédente : |, variables : >>, fichiers : cat*sort|sed 's/.*/\U&/'
ou |tr '[:lower:]' '[:upper:]'
|tr '[:upper:]' '[:lower:]'fichier : find, locate, programme : whereisfind -exec sed -ifichier : head, tail
Python\n \r ou \r\n [7]+*sort()len().upper().lower().find()
inverse : .rfind()
.replace()[].strip()
Ada\n \r ou \r\n [7]chaines : &, commandes : ;*Gnat.Heap_Sort_G[8]variable'SizeCharacters. Handling. To_Upper()Characters. Handling. To_Lower()chaîne(début..fin)
C\n \r ou \r\n [7]chaines : strcat, commandes : ,*, déclaration : ...qsort()sizeof-=32+=32strpbrk(), strchr()strncat()
PHP\n \r ou \r\n [7].*natcasesort()strlen()
tableau : sizeof(), count()
strtoupper()strtolower()strpos()str_replace()substr()trim()
Java\n \r ou \r\n [7]+*Collections.sort().length().toUpperCase().toLowerCase().indexOf(),
regex : .find()
.replaceAll().substring()trim()
JavaScript\n \r ou \r\n [7]+*sort().length.toUpperCase().toLowerCase().indexOf(), .lastIndexOf().replace().substr().trim()
HTML<br/>rienrienrienrienrienrienrienrienrien
SQLrien||, concatlike %...group bycount, lengthupper()[9]lower()[10]like
CHARINDEX()[11]
REPLACE()substring()[12]
Visual Basic_&*len()UCase()LCase()instr()
inverse : instrrev()
replace()left(), mid(), right()
LibO Basic_&*len()
lignes tableau : UBound()
colonnes tableau : LBound
.SearchStringleft(), mid(), right()
LangageAttribut de classeConstructeurLibérationAttendreLister le répertoire courantSortieDate du jourLigne courante
Windows PowerShell (DOS)erase, delpausedirexitdate
Shell Unixrm, rmdirsleep, waitlsexitdate
Pythontype()selfdeltime.sleep()os.path.normcase(f)boucle : break
fonction :
return
import time...import inspect...
Adaautomatiquedelay secondes;
C*, déclaration : ...free()sleep
PHPgettype(), is_numeric()[13], is_int(), is_integer(), is_float(), is_real(), is_double(), is_long(), is_scalar()$this->unset(), unserialize()sleep()__FILE__boucle : break
fonction : return
programme : exit, die
date("d/m/Y")__LINE__
JavainstanceofthisStringBuffer.delete(0, sb.length())
FileInputStream.finalize()
.sleep()File[] files = new File(".").listFiles()fonction : return
programme : System.exit(0);
JavaScriptgetAttribute()thisdeletewindow.setTimeout()object.BuildPath(path, name)return
HTMLrienrienrienrienrien
SQLriendeleteWAITFOR DELAYfonction : RETURNGETDATE()
Visual Basic.save, .saveasSet MaVariable = Nothing
Erase MonTableau[14]
Kill MonFichier ou filesys.DeleteFile MonFichier
Sleep[15]dir()fonction : Exit, End
fichier : .close
goto
now()
LibO Basic.storeToURL()killwaitdir()

Conversions

LangageConnaitre le typeEn entierEn décimalEn caractèreEn chaineDéclarer un tableauLire un tableauTrier un tableau
Pythontype()int()ord()str()
Tableau : " ".join(MaListe)
Tableau = range(1, 2)Tableau[1].sort()
Ada'Value'Image
CStrToInt()itoa()
PHPgettype()intval(), ord()floatval()chr()strval()
Tableau : join()
Objet : json_encode()
$Tableau = array (1 => 'un', 2 => 'deux']);
ou$Tableau[1] = 'un'; $Tableau[2] = 'deux';
$Tableau[1]asort()
Selon plusieurs colonnes : array_multisort()
Java.class .getClass()Integer.parseInt()Float.parseFloat().charAt(0).toString()int [] Tableau = {1,2};Tableau[1],
.arraycopy()
.sort()
JavaScripttypeof()parseInt()toString()var Tableau = new Array(1, 2);Tableau[1].sort()
SQLdescribe Matable Monchamp
T-SQL : SQL_VARIANT_PROPERTY(MonChamp, 'BaseType')
convert()create table Tableauselect * from Tableauorder by
Visual BasicTypename()CInt()CDecrienCStr()Dim Tableau(2) As IntegerTableau(1)rien

Voir aussi Coder avec Unicode/Conversion.

Manipulation de fichiers

LangageOuvrirFermerFin de ficherInsérerTout lireLire une ligneLire un caractèreRechercherViderSupprimerRenommer
Python.open().close().write().readline()
Cfopen()fclose()fputs()fgets()fgetc()fseek()remove()rename()
PHPfopen()fclose()feof()fwrite(), fputs(), file_ put_ contents()file(), file_ get_ contents()fgets()fgetc()fseek()fflush()
JavaFileInputStream().close().readLine()delete().renameTo()
Visual Basicopen.closeeof()printinputline input

Manipulation de fichier Excel

Pour construire un fichier .xls, en plus de la liaison de données de MS-Excel, il est possible de le façonner depuis une base de données, un autre fichier, ou ex-nihilo avec du code :

LangageOuvrirFermerSauvegarderÉcrireParamètres des cellules
PHP PEAR[16]$this->Spreadsheet_Excel_Writer_Workbook($filename);
$workbook = new Spreadsheet_Excel_Writer();
$workbook->close();$workbook->sendFile();$worksheet->write(x,y,'Contenu');$format = $workbook->addFormat(
array(
'Size' => 10,
'Align' => 'center',
'Color' => 'black',
'FgColor' => 'red'));
PHPExcel
Visual Basic[17][18].Workbooks.Open(ActiveWorkbook.Path & "\" & "NomDuFichier").Close.SaveSheets(1).Cells(x,y).Value = "Contenu"
ou Sheets("feuille 1").Range(x & y).Value = "Contenu"
Range(x & y).Font.Size = 10
Range(x & y).HorizontalAlignment = xlCenter
Range(x & y).Font.Color = vbBlack
ou Range(x & y).Font.Colorindex = 2
Range(x & y).Interior.ColorIndex = 4
LibO Basic.storeAsUrl(url,Array()).Close.executeDispatch(document, ".uno:Save", "", 0, Array())getCellByPosition(y, x).value = "Contenu"
ou getCellByName("A1").value = "Contenu"
.CharColor
.cellBackColor
.CharHeight
.CharWeight

Commandes communes aux shells Windows et Unix

  1. cd
  2. date
  3. echo
  4. exit
  5. fdisk
  6. ftp
  7. format
  8. help
  9. hostname
  10. mkdir
  11. more
  12. netstat
  13. nslookup
  14. ping
  15. rmdir
  16. shutdown

Comparatif des shells Windows et Unix

CommandeDOSUnix
Liste des variables d'environnementsetprintenv
Point de montagesubstmount

Regex

Pour plus de détails voir : Catégorie:Expressions rationnelles.
LangageRésultat du premier groupe de capture
Lua%1
Python\1
PHP$1
Java$1
Visual Basic$1

Voir aussi : http://php.net/manual/fr/reference.pcre.pattern.posix.php

Faux-amis

Langageisnull
MySQLRenvoie un booléen
SQL ServerRenvoie une valeur ou une autre selon si la condition est null

Notes et références

  1. Python/Les types de base sur Wikiversité
  2. http://msdn.microsoft.com/fr-fr/library/ms191530%28v=sql.90%29.aspx#_ole_automation
  3. Visual Basic/Les types en VB sur Wikiversité
  4. http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/
  5. http://www.querytool.com/help/1135.htm
  6. http://wiki.services.openoffice.org/wiki/FR/Documentation/BASIC_Guide/Operators
  7. 1 2 3 4 5 6 Le retour à la ligne dépend du système d'exploitation et pas du langage de programmation dont le compilateur ou interpréteur peut être capable d'accepter les trois séquences possibles afin de réutiliser des codes sources provenant de systèmes différents :
    • \n pour Unix, Linux
    • \r pour Mac OS
    • \r\n pour DOS, Windows
  8. http://rosettacode.org/wiki/Sort_an_integer_array#Ada
  9. http://msdn.microsoft.com/fr-fr/library/ms180055.aspx
  10. http://msdn.microsoft.com/fr-fr/library/ms174400.aspx
  11. https://msdn.microsoft.com/fr-fr/library/ms186323%28v=sql.120%29.aspx
  12. http://msdn.microsoft.com/fr-fr/library/ms187748.aspx
  13. Renvoie vrai si la variable est de type numérique, même si elle contient des lettres. Utiliser preg_match ("/[^0-9]/", $nb); dans ce cas
  14. Définit chaque ligne à Nothing
  15. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  16. Programmation PHP/La librairie PEAR DB
  17. Fichiers en VB sur Wikiversité
  18. http://cisternino.free.fr/informatique/excel/vba/cours_vba_excel_fiche_07.pdf

Voir aussi

Cet article est issu de Wikibooks. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.