C#中一些字符串操作的常用用法,c#编码和解码
//获得汉字的区位码
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes("啊");
int i1 = (short)(array[0] - ''\0'');
int i2 = (short)(array[1] - ''\0'');
//unicode解码方式下的汉字码
array = System.Text.Encoding.Unicode.GetBytes("啊");
i1 = (short)(array[0] - ''\0'');
i2 = (short)(array[1] - ''\0'');
//unicode反解码为汉字
string str = "4a55";
string s1 = str.Substring(0,2);
string s2 = str.Substring(2,2);
int t1 = Convert.ToInt32(s1,16);
int t2 = Convert.ToInt32(s2,16);
array[0] = (byte)t1;
array[1] = (byte)t2;
string s = System.Text.Encoding.Unicode.GetString(array);
//default方式反解码为汉字
array[0] = (byte)196;
array[1] = (byte)207;
s = System.Text.Encoding.Default.GetString(array);
//取字符串长度
s = "iam方枪枪";
int len = s.Length;//will output as 6
byte[] sarr = System.Text.Encoding.Default.GetBytes(s);
len = sarr.Length;//will output as 3+3*2=9
//字符串相加
System.Text.StringBuilder sb = new System.Text.StringBuilder("");
sb.Append("i ");
sb.Append("am ");
sb.Append("方枪枪");
/////////////////////////////////////////////////////////////////////
string --> byte array
byte[] data=Syste.Text.Encoding.ASCII.GetBytes(string);
string --> byte
byte data = Convert.ToByte(string);
byte[]-->string
string string = Encoding.ASCII.GetString( bytes, 0, nBytesSize );
C# URL编码与解码
--------------------------------------------------------------------------------
最近做了一个网站统计分析系统,特别在搜索引擎分析那一部分费了不少时间,从已编码的URL中提取搜索关键词再进行解码。主流的搜索引擎中,URL所使用的字符编码都不同,比如,baidu默认是gb2312,google默认是utf-8。而百度用户可以指定utf-8编码。以这两个搜索引擎分析,URL可能是gb2312,也可能是utf-8。头大了!经过几番琢磨。得出一个暂时可以对付的简单方法。
以下是引用片段:
//oStr是UrlEncode编码字符串
Encoding gb2312 = Encoding.GetEncoding("gb2312");
相关文档:
Boss说,要看OpenGL,看了快一个月,总算出了个像样的东西,用C写了个3D迷宫,
虽然只有350行
代码,不过边学边写,足足写了一周时间,还是小有成就感的,活活活!
&n ......
用了别人的代码,推荐+备忘。
原帖地址:
.net(c#)读取flash(swf)文件的尺寸
http://www.cnblogs.com/nasdaqhe/archive/2008/07/02/1234357.html
用.NET读取Flash格式文件信息
http://www.cnblogs.com/gmm/archive/2007/07/17/310675.html
我使用了第一个帖子中的代码,第一个帖子的代码参考的是第二个帖子:)
The ......
2)如何创建一个xml文档
由于xml实质也只是一个文本文件,所以最简单你可以直接使用System.IO下的类生成一个文件,并存储成xml文件,当然,你需要手动保证该文件形式良好,比如必须有根元素、必须有关闭标签、必须正确嵌套等等。
如果你懒得自己去想文件的形式,可以使用System.Xml下的类。
Code
Xml ......
/// <summary>
/// 支持XML序列化的泛型 Dictionary
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
[XmlRoot("SerializableDictionary")]
public class SerializableDictionary<TKey, TValue& ......
RT。先贴代码
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Value_Ref_test1
{
class Program
{
static void Main(string[] args)
{
point a = new point (10,10) ;
point b = a;
......