当前位置: 首页>>代码示例>>C#>>正文


C# UTF8Encoding.GetString方法代码示例

本文整理汇总了C#中System.Text.UTF8Encoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetString方法的具体用法?C# UTF8Encoding.GetString怎么用?C# UTF8Encoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UTF8Encoding的用法示例。


在下文中一共展示了UTF8Encoding.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetConvertion

        public decimal GetConvertion(string from, string to)
        {
            WebClient objWebClient = null;
            UTF8Encoding objUTF8 = null;
            decimal result = 0;

            try{
                objWebClient = new WebClient();
                objUTF8 = new UTF8Encoding();

                byte[] aRequestedHTML = objWebClient.DownloadData(String.Format("http://www.xe.com/ucc/convert/?Amount=1&From={0}&To={1}", from, to));
                string strRequestedHTML = objUTF8.GetString(aRequestedHTML);

                int search1 = strRequestedHTML.LastIndexOf("&nbsp;<span class=\"uccResCde\">USD</span>");
                string search2 = strRequestedHTML.Substring(search1 - 21, 21);
                int search3 = search2.LastIndexOf(">");
                string stringRepresentingCE = search2.Substring(search3 + 1);

                result = Convert.ToDecimal(stringRepresentingCE.Trim());

            }
            catch (Exception ex){
                // Agregar codigo para manejar la excepción.
            }

            return result;
        }
开发者ID:nalia2015,项目名称:tusegurodeviaje1,代码行数:27,代码来源:conversiondemonedas.cs

示例2: Parse

        public static NameValueCollection Parse(Stream stream)
        {
            Dictionary<string, string[]> form = new Dictionary<string, string[]>();
            UTF8Encoding encoding = new UTF8Encoding(false);

            return HttpUtility.ParseQueryString(encoding.GetString(stream.ReadAllBytes()),encoding);
        }
开发者ID:sgarver,项目名称:RadMVC,代码行数:7,代码来源:FormParser.cs

示例3: GetSha1Hash

 public static string GetSha1Hash(this string value)
 {
     var encoding = new UTF8Encoding();
     var hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     var hashed = hash.ComputeHash(encoding.GetBytes(value));
     return encoding.GetString(hashed);
 }
开发者ID:MrHayato,项目名称:PhotoCache,代码行数:7,代码来源:StringExtensions.cs

示例4: Base64Decode

        /// <summary>
        /// Base64 Decode
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static string Base64Decode(string src)
        {
            string sReturn = "";

            if (src != "")
            {
                byte[] arr = null;
                UTF8Encoding uniEnc = null;

                try
                {
                    uniEnc = new UTF8Encoding();
                    arr = Convert.FromBase64String(src);
                    sReturn = uniEnc.GetString(arr);
                }
                catch
                {
                }
                finally
                {
                    uniEnc = null;
                }
            }
            return sReturn;
        }
开发者ID:sunyruru,项目名称:ruru-library,代码行数:30,代码来源:Base64Convert.cs

示例5: Encode

        protected string Encode(string value)
        {
            UTF8Encoding encoding = new UTF8Encoding();

            switch (_DataType.Encoding)
            {
                case "BASE64": return Convert.ToBase64String(encoding.GetBytes(value));
                case "7BIT":
                case "8BIT":                
                    value = Regex.Replace(value, @"[^\r]\n", "\r\n");
                    value = Regex.Replace(value, @"\r[^\n]", "\r\n");

                    bool is7Bit = _DataType.Encoding.Equals("7BIT");

                    List<byte> data = new List<byte>(encoding.GetBytes(value));
                    for (int i = data.Count - 1; i >= 0; i--)
                    {
                        if (data[i] == 0)
                            data.RemoveAt(i);

                        if (is7Bit && data[i] > 127)
                            data.RemoveAt(i);
                    }

                    return encoding.GetString(data.ToArray());
                default:
                    return value;
            }
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:29,代码来源:EncodableDataTypeSerializer.cs

示例6: Run

        private static async Task<int> Run(int port) {
            using (var client = new TcpClient()) {
                await client.ConnectAsync(IPAddress.Loopback, port);

                var utf8 = new UTF8Encoding(false);
                using (var reader = new StreamReader(client.GetStream(), utf8, false, 4096, true))
                using (var writer = new StreamWriter(client.GetStream(), utf8, 4096, true)) {
                    var filename = await reader.ReadLineAsync();
                    var args = (await reader.ReadLineAsync()).Split('|')
                        .Select(s => utf8.GetString(Convert.FromBase64String(s)))
                        .ToList();
                    var workingDir = await reader.ReadLineAsync();
                    var env = (await reader.ReadLineAsync()).Split('|')
                        .Select(s => s.Split(new[] { '=' }, 2))
                        .Select(s => new KeyValuePair<string, string>(s[0], utf8.GetString(Convert.FromBase64String(s[1]))))
                        .ToList();
                    var outputEncoding = await reader.ReadLineAsync();
                    var errorEncoding = await reader.ReadLineAsync();

                    return await ProcessOutput.Run(
                        filename,
                        args,
                        workingDir,
                        env,
                        false,
                        new StreamRedirector(writer, outputPrefix: "OUT:", errorPrefix: "ERR:"),
                        quoteArgs: false,
                        elevate: false,
                        outputEncoding: string.IsNullOrEmpty(outputEncoding) ? null : Encoding.GetEncoding(outputEncoding),
                        errorEncoding: string.IsNullOrEmpty(errorEncoding) ? null : Encoding.GetEncoding(errorEncoding)
                    );
                }
            }
        }
开发者ID:zooba,项目名称:PTVS,代码行数:34,代码来源:Program.cs

示例7: GetDecryptedText

        public static string GetDecryptedText(string EncryptedString)
        {
            string sdec = "";
            try
            {
                string smsg = EncryptedString;

                DESCryptoServiceProvider des = new DESCryptoServiceProvider();

                System.Text.Encoding utf = new System.Text.UTF8Encoding();

                byte[] key = utf.GetBytes("12348765");
                byte[] iv ={ 1, 2, 3, 4, 8, 7, 6, 5 };

                ICryptoTransform decryptor = des.CreateDecryptor(key, iv);

                byte[] bmsg = utf.GetBytes(smsg);

                byte[] benc1 = System.Convert.FromBase64String(EncryptedString);
                byte[] bdec = decryptor.TransformFinalBlock(benc1, 0, benc1.Length);
                sdec = utf.GetString(bdec);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return sdec;
        }
开发者ID:guarddoggps,项目名称:xtremek,代码行数:28,代码来源:EncDec.cs

示例8: Can_put_and_get_an_attachment

		public IEnumerable<Task> Can_put_and_get_an_attachment()
		{
			var store = new DocumentStore {Url = Url + Port};
			store.Initialize();

			var dbname = GenerateNewDatabaseName();
			yield return store.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

			const string someData = "The quick brown fox jumps over the lazy dog";
			var encoding = new UTF8Encoding();
			var bytes = encoding.GetBytes(someData);

			yield return store.AsyncDatabaseCommands
				.ForDatabase(dbname)
				.PutAttachmentAsync("123", Guid.Empty, bytes, null);

			var get = store.AsyncDatabaseCommands
				.ForDatabase(dbname)
				.GetAttachmentAsync("123");
			yield return get;
			
			var returnedBytes = get.Result.Data().ReadData(); 
			var returned = encoding.GetString(returnedBytes,0,returnedBytes.Length);

			Assert.AreEqual(someData, returned);
		}
开发者ID:runesoerensen,项目名称:ravendb,代码行数:26,代码来源:Attachments.cs

示例9: getApiKey

        static void getApiKey()
        {
            string path = ".apikey";

            if (!File.Exists(path))
            {
                using (FileStream fs = File.Create(path))
                {

                    var NewApiKey = "";
                    Console.WriteLine(@"There is no steam API key set. To get an api key, vist https://steamcommunity.com/dev/apikey.");

                    while (NewApiKey.Length != 32)
                    {
                        Console.WriteLine("Please enter your API key : ");
                        NewApiKey = Console.ReadLine();
                        if (NewApiKey.Length != 32)
                            Console.WriteLine("Your API key is invalid, please enter a valid 32 character API key.");
                    }

                    AddText(fs, NewApiKey);
                }
            }

            var apikey = "";
            using (var fs = File.Open(".apikey", FileMode.Open, FileAccess.Read))
            {
                byte[] b = new byte[1024];
                UTF8Encoding temp = new UTF8Encoding(true);
                fs.Read(b, 0, b.Length);
                apikey = temp.GetString(b);
            }
            steamApiKey = apikey;
        }
开发者ID:sirlag,项目名称:Entropy,代码行数:34,代码来源:Program.cs

示例10: ObjectToXml

        /// <summary>
        /// Converts the object to xml string.
        /// </summary>
        /// <param name="obj">The object to be serialized</param>
        /// <param name="toBeIndented"><c>true</c> if wants the xml string was indented, otherwise <c>false</c>.</param>
        /// <returns>The xml string.</returns>
        public static string ObjectToXml(object obj, bool toBeIndented)
        {
            if (null == obj)
            {
                throw new ArgumentNullException("obj");
            }
            UTF8Encoding encoding = new UTF8Encoding(false);
            XmlSerializer serializer = new XmlSerializer(obj.GetType());
            MemoryStream stream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(stream, encoding);
            writer.Formatting = (toBeIndented ? Formatting.Indented : Formatting.None);

            try
            {
                serializer.Serialize(writer, obj);
            }
            catch (InvalidOperationException)
            {
                throw new InvalidOperationException("Can not convert object to xml.");
            }
            finally
            {
                writer.Close();
            }
            string xml = encoding.GetString(stream.ToArray());
            return xml;
        }
开发者ID:dayuhan,项目名称:NETWORK,代码行数:33,代码来源:XmlConvertor.cs

示例11: getCoordinates

        public static decimal[] getCoordinates(string address1, string address2,
            string city, string state, string zipcode, string appId)
        {
            string retVal;
            decimal[] coordinates = new decimal[2];

            System.Net.WebClient webClient = new System.Net.WebClient();
            string request = "http://where.yahooapis.com/geocode?location="
                + address1 + "+" + address2 + "+" + city + "+" + state + "+" + zipcode
                + "&" + appId;

            byte[] responseXML;
            try
            {
                responseXML = webClient.DownloadData(request);
                System.Text.UTF8Encoding objUTF8 = new System.Text.UTF8Encoding();
                retVal = objUTF8.GetString(responseXML) + "\n";
            }
            catch (System.Exception ex)
            {
                retVal = ex.Message;
            }

            // parse the return values
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(retVal);
            XmlNode ndLatitude = xml.SelectSingleNode("//latitude");
            XmlNode ndLongitude = xml.SelectSingleNode("//longitude");

            coordinates[0] = Convert.ToDecimal(ndLatitude.InnerText);
            coordinates[1] = Convert.ToDecimal(ndLongitude.InnerText);

            return coordinates;
        }
开发者ID:ManigandanS,项目名称:Disaster-Management-Communication-System,代码行数:34,代码来源:GeoLocation.cs

示例12: Main

		static void Main (string[] args)
		{
			if (args.Length != 1) {
				Console.WriteLine ("Usage: TestAsyncStream <uri>");
				return;
			}
		
			Gnome.Vfs.Vfs.Initialize ();

			VfsStream stream = new VfsStream (args[0], FileMode.Open, true);
			
			UTF8Encoding utf8 = new UTF8Encoding ();
			buffer = new byte[1024];
			int read;
			while ((read = stream.Read (buffer, 0, buffer.Length)) != 0) {
				Console.WriteLine ("read ({0} bytes) : '{1}'",
						   read, utf8.GetString (buffer, 0, read));
			}

			long offset = stream.Seek (0, SeekOrigin.Begin);
			Console.WriteLine ("Offset after seek is {0}", offset);
			
			buffer = new byte[1024];
			IAsyncResult result = stream.BeginRead (buffer, 0, buffer.Length,
								new System.AsyncCallback (OnReadComplete),
								stream);

			loop = new MainLoop ();
			loop.Run ();

			Gnome.Vfs.Vfs.Shutdown ();
		}
开发者ID:directhex,项目名称:xamarin-gnome-sharp2,代码行数:32,代码来源:TestAsyncStream.cs

示例13: RequestGetToUrl

        private static string RequestGetToUrl(string url)
        {
            WebProxy proxy = WebProxy.GetDefaultProxy();
            if (string.IsNullOrEmpty(url))
                return null;

            if (url.IndexOf("://") <= 0)
                url = "http://" + url.Replace(",", ".");

            try
            {
                using (var client = new WebClient())
                {
                    //proxy
                    if (proxy != null)
                        client.Proxy = proxy;

                    //response
                    byte[] response = client.DownloadData(url);
                    //out
                    var enc = new UTF8Encoding();
                    string outp = enc.GetString(response);
                    return outp;
                }
            }
            catch (WebException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
            return null;
        }
开发者ID:msx752,项目名称:OPALOP-Picture-Mosaic,代码行数:35,代码来源:InstagramProfile.cs

示例14: Main

        static void Main(string[] args)
        {
            //Console.WriteLine("Test");
            //Console.ReadLine();
            WebClient wc = new WebClient();

            string WebURL = @"http://localhost:50316/service.asmx";//@"http://www.google.co.th";
            UTF8Encoding encUTF8 = new UTF8Encoding();
            string returnedData = "";

            try
            {
                Console.WriteLine(WebURL);
                Console.WriteLine("Connecting...");

                returnedData = encUTF8.GetString(wc.DownloadData(WebURL));

                Console.WriteLine(returnedData);
                Console.WriteLine("Download data complete ");

            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR :: " + ex.Message);
            }
            Console.ReadLine();
        }
开发者ID:kratin,项目名称:httpService,代码行数:27,代码来源:Program.cs

示例15: Decrypt

        public string Decrypt(string message)
        {
            byte[] results;
            UTF8Encoding utf8 = new UTF8Encoding();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] deskey = md5.ComputeHash(utf8.GetBytes(Passphrase));
            TripleDESCryptoServiceProvider desalg = new TripleDESCryptoServiceProvider();
            desalg.Key = deskey;
            desalg.Mode = CipherMode.ECB;
            desalg.Padding = PaddingMode.PKCS7;
            byte[] decryptData = Convert.FromBase64String(message);
            try
            {
                //To transform the utf binary code to md5 decrypt
                ICryptoTransform decryptor = desalg.CreateDecryptor();
                results = decryptor.TransformFinalBlock(decryptData, 0, decryptData.Length);
            }
            finally
            {
                desalg.Clear();
                md5.Clear();

            }
            //TO convert decrypted binery code to string
            return utf8.GetString(results);
        }
开发者ID:saditya90,项目名称:MvcPlugin,代码行数:26,代码来源:Helper.cs


注:本文中的System.Text.UTF8Encoding.GetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。