begin process at 2010 03 22 00:48:44
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

.NET

 > [C#] CONVERSION DE CHAÎNE 'STRING' VERS CHAÎNE 'DÉCIMAL' ET RÉCIPROQUEMENT

[C#] CONVERSION DE CHAÎNE 'STRING' VERS CHAÎNE 'DÉCIMAL' ET RÉCIPROQUEMENT


 Information sur la source

Note :
7,67 / 10 - par 3 personnes
7,67 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :.NET Source .NET ( DotNet ) Classé sous :tranformation, conversion, chaine, string, decimal Niveau :Débutant Date de création :15/07/2004 Vu :25 095

Auteur : scoubidou944

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Un bon exemple valant mieux qu'une tonne de commentaires :

string szStr, szStr2, szStr3;

szStr = "abcdefghijklmnopqrstuvwxyz";
szStr2 = ConvertAsciiStringToHexaString (szStr);
szStr3 = ConvertHexaStringToAsciiString (szStr2);

szStr = "Unicode character Pi(\u03a0)";
szStr2 = ConvertUnicodeStringToHexaString (szStr);
szStr3 = ConvertHexaStringToUnicodeString (szStr2);

Source

  • /// <summary>
  • /// Convert a string like 'abcdefghijklmnopqrstuvwxyz' to decimal string like '6162636465666768696A6B6C6D6E6F707172737475767778797A'
  • /// ONLY UNICODE IN THIS FUNCTION
  • /// </summary>
  • /// <param name="_szStr">String to convert</param>
  • /// <returns></returns>
  • public string ConvertUnicodeStringToHexaString (string _szStr)
  • {
  • string szResult = String.Empty;
  • byte[] abytesText = Encoding.Unicode.GetBytes(_szStr);
  • foreach (byte a in abytesText)
  • {
  • if (a<16)
  • szResult += "0" + a.ToString ("X");
  • else
  • szResult += a.ToString ("X");
  • }
  • return szResult;
  • }
  • /// <summary>
  • /// Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz'
  • /// ONLY UNICODE IN THIS FUNCTION
  • /// </summary>
  • /// <param name="_szStr">String to convert</param>
  • /// <returns></returns>
  • public string ConvertHexaStringToUnicodeString (string _szStr)
  • {
  • int iOffset = 0;
  • string szResult = String.Empty;
  • byte[] abytesText = new byte [_szStr.Length /2];
  • for (int i = 0; i < _szStr.Length /2; i++)
  • {
  • abytesText [iOffset] = (byte)Int32.Parse(_szStr.Substring(i*2,2), System.Globalization.NumberStyles.HexNumber);
  • iOffset++;
  • }
  • char[] asciiChars = new char[Encoding.Unicode.GetCharCount(abytesText, 0, abytesText.Length)];
  • Encoding.Unicode.GetChars(abytesText, 0, abytesText.Length, asciiChars, 0);
  • szResult = new string(asciiChars);
  • return szResult;
  • }
  • /// <summary>
  • /// Convert a string like 'abcdefghijklmnopqrstuvwxyz' to decimal string like '6162636465666768696A6B6C6D6E6F707172737475767778797A'
  • /// ONLY ASCII IN THIS FUNCTION
  • /// </summary>
  • /// <param name="_szStr">String to convert</param>
  • /// <returns></returns>
  • public string ConvertAsciiStringToHexaString (string _szStr)
  • {
  • string szResult = String.Empty;
  • byte[] abytesText = Encoding.ASCII.GetBytes(_szStr);
  • foreach (byte a in abytesText)
  • {
  • if (a<16)
  • szResult += "0" + a.ToString ("X");
  • else
  • szResult += a.ToString ("X");
  • }
  • return szResult;
  • }
  • /// <summary>
  • /// Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz'
  • /// ONLY ASCII IN THIS FUNCTION
  • /// </summary>
  • /// <param name="_szStr">String to convert</param>
  • /// <returns></returns>
  • public string ConvertHexaStringToAsciiString (string _szStr)
  • {
  • int iOffset = 0;
  • string szResult = String.Empty;
  • byte[] abytesText = new byte [_szStr.Length /2];
  • for (int i = 0; i < _szStr.Length /2; i++)
  • {
  • abytesText [iOffset] = (byte)Int32.Parse(_szStr.Substring(i*2,2), System.Globalization.NumberStyles.HexNumber);
  • iOffset++;
  • }
  • char[] asciiChars = new char[Encoding.ASCII.GetCharCount(abytesText, 0, abytesText.Length)];
  • Encoding.ASCII.GetChars(abytesText, 0, abytesText.Length, asciiChars, 0);
  • szResult = new string(asciiChars);
  • return szResult;
  • }
/// <summary>
		/// Convert a string like 'abcdefghijklmnopqrstuvwxyz' to decimal string like '6162636465666768696A6B6C6D6E6F707172737475767778797A'
		/// ONLY UNICODE IN THIS FUNCTION
		/// </summary>
		/// <param name="_szStr">String to convert</param>
		/// <returns></returns>
		public string ConvertUnicodeStringToHexaString (string _szStr)
		{
			string szResult		= String.Empty;
			byte[] abytesText	= Encoding.Unicode.GetBytes(_szStr);

			foreach (byte a in abytesText)
			{
				if (a<16)
					szResult += "0" + a.ToString ("X");
				else
					szResult += a.ToString ("X");
			}
			return szResult;
		}

		/// <summary>
		/// Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz'
		/// ONLY UNICODE IN THIS FUNCTION
		/// </summary>
		/// <param name="_szStr">String to convert</param>
		/// <returns></returns>
		public string ConvertHexaStringToUnicodeString (string _szStr)
		{
			int		iOffset		= 0;
			string	szResult	= String.Empty;
			byte[]	abytesText	= new byte [_szStr.Length /2];

			for (int i = 0; i < _szStr.Length /2; i++)
			{
				abytesText [iOffset] = (byte)Int32.Parse(_szStr.Substring(i*2,2), System.Globalization.NumberStyles.HexNumber);
				iOffset++;
			}

			char[] asciiChars = new char[Encoding.Unicode.GetCharCount(abytesText, 0, abytesText.Length)];
			Encoding.Unicode.GetChars(abytesText, 0, abytesText.Length, asciiChars, 0);
			szResult = new string(asciiChars);

			return szResult;
		}

		/// <summary>
		/// Convert a string like 'abcdefghijklmnopqrstuvwxyz' to decimal string like '6162636465666768696A6B6C6D6E6F707172737475767778797A'
		/// ONLY ASCII IN THIS FUNCTION
		/// </summary>
		/// <param name="_szStr">String to convert</param>
		/// <returns></returns>
		public string ConvertAsciiStringToHexaString (string _szStr)
		{
			string szResult		= String.Empty;
			byte[] abytesText	= Encoding.ASCII.GetBytes(_szStr);

			foreach (byte a in abytesText)
			{
				if (a<16)
					szResult += "0" + a.ToString ("X");
				else
					szResult += a.ToString ("X");
			}
			return szResult;
		}

		/// <summary>
		/// Convert a string like '6162636465666768696A6B6C6D6E6F707172737475767778797A' to decimal string like 'abcdefghijklmnopqrstuvwxyz'
		/// ONLY ASCII IN THIS FUNCTION
		/// </summary>
		/// <param name="_szStr">String to convert</param>
		/// <returns></returns>
		public string ConvertHexaStringToAsciiString (string _szStr)
		{
			int		iOffset		= 0;
			string	szResult	= String.Empty;
			byte[]	abytesText	= new byte [_szStr.Length /2];

			for (int i = 0; i < _szStr.Length /2; i++)
			{
				abytesText [iOffset] = (byte)Int32.Parse(_szStr.Substring(i*2,2), System.Globalization.NumberStyles.HexNumber);
				iOffset++;
			}

			char[] asciiChars = new char[Encoding.ASCII.GetCharCount(abytesText, 0, abytesText.Length)];
			Encoding.ASCII.GetChars(abytesText, 0, abytesText.Length, asciiChars, 0);
				
			szResult = new string(asciiChars);
			return szResult;
		}

 Conclusion

Pour tous ceux qui utilisent du cryptage (AES par exemple qui a le don de produire des chaînes avec des caractères ASCII à la con), voilà comment comment convertir une chaîne vers sa valeur décimale lisible dans n'importe quel fichier TXT.


 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) [C#] [XML] SERIALIZATION STRING, COLOR, ARRAYLIST, HASHTABLE...
Source avec Zip Source avec une capture Source .NET (Dotnet) [C#] COLLAPSIBLE PANEL
Source avec Zip Source avec une capture Source .NET (Dotnet) TREELISTVIEW
Source avec Zip Source avec une capture Source .NET (Dotnet) [C#] [TUTORIAL BASIQUE] STÉGANOGRAPHIE IMAGE BITMAP
Source .NET (Dotnet) [C#] TUTORIAL BASIQUE (FICHIER BINAIRE, SÉRIALISATION)

 Sources de la même categorie

Source avec Zip CHAT SERVER-CLIENT par abderrahmenbilog
Source avec Zip Source avec une capture Source .NET (Dotnet) SIMULATION DE CONSOLE POUR WINDOWS MOBILE par originalcompo
Source avec Zip Source .NET (Dotnet) BASE DE DONNÉES EN XML par DanMor498
Source avec Zip Source avec une capture Source .NET (Dotnet) SIMPLECONV - APPLICATION DE CONVERSION MONÉTAIRE AVEC TAUX E... par Jeffrey_
Source avec Zip Source .NET (Dotnet) TRAITEUR D'IMAGE (MINI) par ycyril

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) GESTION DES LANGUES, COUNTRIES, CHAÎNES DE CARACTÈRE SIMPLE par gourky
Source avec Zip Source avec une capture Source .NET (Dotnet) SIMPLECONV - APPLICATION DE CONVERSION MONÉTAIRE AVEC TAUX E... par Jeffrey_
Source avec Zip Source .NET (Dotnet) DATE EN TOUTE LETTRE (ARABE) par moi2007
Source .NET (Dotnet) CONVERSION ASCII-8 - BINAIRE par badrbadr
Source avec Zip Source .NET (Dotnet) UNE DLL QUI CONTIENT TOUTES LES METHODES DE CONVERSION D'UN ... par lino03

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Conversion d'un string en XML [ par swyms ] Bonjour à tous,Comment faire pour convertir une chaine en un objet XML ?En fait, j'ai une chaine de caractère correctement formatté avec les balises q Conversion d'une chaine String en Class [ par PROTEUS91 ] Bonjour, Je poste ce message car je ne trouve pas de solution a mon problème. J'ai une chaine string : string _sClassName="MyClass" La classe MyCl Problèeme de conversion int en string [ par florianj54 ] Bonjour, j'ai une liste une liste d'objet animaux et je récupère leur type, si c'est un felin, un rapace etc .. seulement quand je veux afficher le Conversion string - octet [ par trdev ] Bonjourje dois récupérer les infos d'un champs Acces (texte) d'une application.D'apres l'éditeur les champs est un  octet binaire encadré de guillemet covertir string en float [ par baby85 ] bonsoir,je suis débutante en c# et je veux savoir comment peux-je convertir une chaine de caractére string en float avec cette chaine  est le résultat Ecriture en mémoire d'une chaine de caractère [ par ScRunCHy ] Salut à tous,Dans mon code en C#, je récupère une string qui est écrite dans un fichier XML de config. Mon but est d'obtenir un char*.J'ai d'abord uti délimiter mon string dans un tableau [ par bisoubebe ] bonjour j'ai crée une fonction qui doit recevoir une chaine sur cette forme "p98 p65 p963 p8475"et me retourner une structure ayantun élément par exam Algo pour RTF [ par bmouget ] Bonjour,Je voudrais réorganiser une chaine de caractère RTF en plusieurs tableaux de string.Je cherche donc un algo capable de structurer une chaine d C# help: pb de conversion string en integer [ par vdekeuwer ] Bonjour,je fait un programme pour lire des données sur un puce RFID,je récupère grace au lecteurRFID , Data qui est un byteArray, pour lire la donnée Conversion caractères [ par Anne56 ] Bonjour, Voici mon problème. J'ai une base de données Access dans laquelle est stocké des chaines de caractères en chinois, en letton et je veux pouvo


Nos sponsors


Sondage...

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,858 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales