Les Snippets

Connexion

Supprimer les retour-chariots d'une variable fournie

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 18/04/2006 23:59:39 et initié par fabrice69 [Liste]
Vue : 30498
Catégorie(s) : Chaîne de caractères
Langages dispo pour ce code :
- SQL, SQL 2005
- PHP 3, PHP 4, PHP 5
- C# 1.x, C# 2.x
- mySQL
- Java
- VB6, VBA
- C
- Javascript
- VB 2005, VB 2008, VB.NET 1.x



Langage : SQL , SQL 2005
Date ajout : 18/04/2006
Posté par fabrice69 [Liste]
SELECT
 REPLACE(REPLACE(MonChampAvecCRLF, CHAR(13), ' '), CHAR(10), ' ') AS MonChampSansCRLF,
FROM 
 MaTable;

Remarque :
Attention, cela fonctionne avec SQL Server
Romelard Fabrice
Langage : PHP 3 , PHP 4 , PHP 5
Date ajout : 19/04/2006
Posté par k@se [Liste]
/*
Pour informations:
 CR : Carriage Return ( 0x0D )
 LF : Line Feed ( 0x0A )
*/
$myVarsWithoutCRLF = str_replace(array("\n","\r")," ",$myVars);


Langage : C# 1.x , C# 2.x
Date ajout : 19/04/2006
Posté par k@se [Liste]

string myVarsWithoutCRLF = myVar.Replace("\n", " ").Replace("\r"," ");

Langage : mySQL
Date ajout : 19/04/2006
Posté par k@se [Liste]
select 
    replace(replace(myField,"\n"," "),"\r"," ") 
from 
    myTable
Langage : Java
Date ajout : 11/05/2006
Posté par Arglanir [Liste]

public static String enleveRC(String texte){
    return texte.replaceAll("[\n\r]+"," ");
}

Langage : VB6 , VBA
Date ajout : 15/07/2006
Posté par PCPT [Liste]
Function ReplaceCRLF(sStr As StringOptional sSepar As String = " ") As String 
    ReplaceCRLF = Replace(sStr, vbCrLf, sSepar) 
End Function
Langage : C
Date ajout : 16/07/2006
Posté par BruNews [Liste]

Pendant qu'on y sera, on retourne le pointeur sur fin de chaine nettoyée pour éviter tout strcat et donc chainer directement si besoin.

char* strRemoveCRLF(char *psz)
{
  char *d = psz; // POINTEUR D'ECRITURE
  while(*psz) {
    if((*psz != '\r') && (*psz != '\n')) *d++ = *psz;
    psz++;
  }
  *d = 0;
  return d;
}


Langage : Javascript
Date ajout : 05/04/2007
Posté par stfou [Liste]
function line(variable){variable=variable.split("\n").join();}
Langage : VB.NET 1.x , VB 2005 , VB 2008
Date ajout : 08/12/2008
Posté par Charles Racaud [Liste]
Public Function RemoveNewLine(ByVal Text As StringAs String
  Return RemoveNewLine(Text, String.Empty)
End Function
Public Function RemoveNewLine(ByVal Text As StringByVal ReplaceStr As StringAs String
  Return Text.Replace(Environment.NewLine, ReplaceStr)
End Function



Codes sources en rapport avec : Retour chariot, Vbcr, Crlf, Enter

{SQL} SQL SERVER - COMMENT SUPPRIMER LES RETOUR-CHARIOT D'UN CHAMP TEXTE
Dans de nombreux cas, on se retrouve avec des champs texte contenant des retour-chariot que l'on vou...

{Delphi} DÉPLACER LE FOCUS D'UN TEDIT À L'AUTRE EN IGNORANT LES AUTRES COMPOSANTS
Permet de mettre le focus sur l'Edit suivant ou l'Edit précédent en fonction de la touche pressée, e...