本文整理汇总了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(" <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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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)
);
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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 ();
}
示例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;
}
示例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();
}
示例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);
}