Outils pour utilisateurs

Outils du site


lang:csharp:textes

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
lang:csharp:textes [2016/11/03 11:18] – Ajout de "Concaténation de string" rootlang:csharp:textes [2020/04/28 21:18] (Version actuelle) – mhtml -> html root
Ligne 32: Ligne 32:
 </code> </code>
  
-[[http://stackoverflow.com/questions/333737/evaluating-string-342-yield-int-18|Source]]{{ :lang:csharp:textes:c_-_evaluating_string_3_4_2_yield_int_18_-_stack_overflow.maff |Archive}}+[[http://stackoverflow.com/questions/333737/evaluating-string-342-yield-int-18|c# - Evaluating string _3_(4+2)_ yield int 18 - Stack Overflow]] {{ :lang:csharp:textes:c_-_evaluating_string_3_4_2_yield_int_18_-_stack_overflow_2020-04-28_9_13_20_pm_.html |Archive du 02/12/2008 le 28/04/2020}}
  
 =====Concaténation de string===== =====Concaténation de string=====
Ligne 38: Ligne 38:
 <code csharp> <code csharp>
 StringBuilder stringBuilder = new StringBuilder("Début"); StringBuilder stringBuilder = new StringBuilder("Début");
-stringBuilder.Append("coucou");+stringBuilder.Append("coucou").Append(", bien le bonjour.");
 string finalement = stringBuilder.ToString(); string finalement = stringBuilder.ToString();
 +</code>
 +
 +=====Valeur numérique d'un caractère=====
 +Un simple cast.
 +<code csharp>
 +int val = (int) 'Y';
 +</code>
 +
 +[[http://stackoverflow.com/questions/3414900/how-to-get-a-char-from-an-ascii-character-code-in-c-sharp|How to get a Char from an ASCII Character Code in c# - Stack Overflow]] {{ :lang:csharp:textes:how_to_get_a_char_from_an_ascii_character_code_in_c_-_stack_overflow_2020-04-28_9_13_17_pm_.html |Archive du 05/08/2010 le 28/04/2020}}
 +
 +Cependant, cela ne marche pas forcément très bien en fonction des besoins : le symbole ''œ'' renverra 339 et non pas 156.
 +
 +Pour récupérer 156, il faut :
 +<code csharp>
 +Encoding.Default.GetBytes("œ")[0];
 +</code>
 +
 +=====Expression régulière=====
 +<code csharp>
 +Regex regex = new Regex(@"^.*:\s*DB\s*(.*)(,.*)*(;.*)?$");
 +
 +Match match = regex.Match(texte);
 +
 +if (match.Success)
 +{
 +  Console.WriteLine(match.Groups[0].Value);
 +}
 +</code>
 +
 +[[https://www.dotnetperls.com/regex|C# Regex.Match Examples_ Regular Expressions - Dot Net Perls]] {{ :lang:csharp:textes:c_regex.match_examples_regular_expressions_-_dot_net_perls_2020-04-28_9_13_15_pm_.html |Archive le 28/04/2020}}
 +
 +=====Le caractère null=====
 +Pour déterminer la longueur d'une chaîne de caractère, on utilise la propriété ''Length'', là où en ''C'', on recherche le caractère ''null''.
 +
 +Mais il peut arriver qu'une chaîne de caractère (en ''C#'') possède un caractère ''null''. Pour vérifier sa présence, il faut faire tout simplement :
 +<code csharp>
 +texte.IndexOf('\0') != -1
 +</code>
 +
 +=====Comparaison insensible à la casse=====
 +<code csharp>
 +StartsWith("texte", StringComparison.OrdinalIgnoreCase);
 +EndsWith("texte", StringComparison.OrdinalIgnoreCase);
 +IndexOf("texte", StringComparison.OrdinalIgnoreCase);
 +Equals("texte1", "texte2", StringComparison.OrdinalIgnoreCase);
 </code> </code>
lang/csharp/textes.1478168314.txt.gz · Dernière modification : 2016/11/03 11:18 de root