String to getbytes
string-to-getbytes.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this section create a string variable.
string plant = "Laurel";
Label1.Text = "string of plant..................<br />";
Label1.Text += plant;
//convert string to byte array using various encoding.
byte[] bytes = Encoding.ASCII.GetBytes(plant);
byte[] bytesDefault = Encoding.Default.GetBytes(plant);
byte[] bytesUTF8 = Encoding.UTF8.GetBytes(plant);
Label1.Text += "<br /><br />bytes from string (encoding ASCII)........";
foreach (byte b in bytes)
{
//represent the ASCII code of characters.
Label1.Text += "<br />" + b;
}
Label1.Text += "<br /><br />bytes from string (encoding default)........";
foreach (byte b in bytesDefault)
{
//default encoding of characters.
Label1.Text += "<br />" + b;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string to getbytes</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string to getbytes
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="string to getbytes"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to format a string as a date without time
- How to format a string as decimal
- How to format a string as datetime yyyyMMdd
- How to convert a string to double
- How to convert a string to a float array
- How to write a string to a file
- How to convert a string to an int list
- How to convert a string to an IP address
- How to convert a string to an int array
- How to split a string to key value pairs