关于string的length
在C++里面,std::string的length()返回的是字节数,与编码方式有关。
int main()
{
std::string s = "我是中国人";
std::cout << s.length() << std::endl;
std::cout << strlen(s.c_str()) << std::endl;
}
上面的代码,使用GB2312编码,输出结果是10和10.
而在C#里面,string.Length属性返回的是字符数,与编码方式无关。
static void Main(string[] args)
{
string s = "我是中国人";
Console.WriteLine(s.Length);
Console.WriteLine(Encoding.UTF8.GetBytes(s).Length);
}
上面代码输出结果是5和15.
关于string的length的更多相关文章
- WCF常见异常-The maximum string content length quota (8192) has been exceeded while reading XML data
异常信息:The maximum string content length quota (8192) has been exceeded while reading XML data 问题:调用第三 ...
- The maximum string content length quota (8192) has been exceeded while reading XML data
原文:The maximum string content length quota (8192) has been exceeded while reading XML data 问题场景:在我们W ...
- String.length()和String.getBytes().length
1.字符与字节 抛出如下代码: public static void main(String[] args) { String str = "活出自己范儿"; System.out ...
- ord() expected string of length 1, but int found
源代码是这样: s=b'^SdVkT#S ]`Y\\!^)\x8f\x80ism' key='' for i in s: i=ord(i)-16 key+=chr(i^32) prin ...
- java - 数组与String的length方法问题
java数组没有length()方法,java数组有length属性: String有length()方法.
- String的length()和Array的length
String是个final修饰的最终类,不能被继承,String中属性都设置为private,方法为public,并不提供set方法,想要获得字符串的长度必须调用length()方法这个长度是确定的, ...
- string.trim().length()的用法
public class Test{ public static void main(String args[]){ String data = " a bc "; //调用str ...
- String 对象-->length 属性
1.定义和用法 length 属性返回字符串的长度(字符数). 语法: string.length 注意:根据各国字符长度计算长度 举例: var str = 'abner pan' console. ...
- 调用WebServiceWebService提示The maximum string content length quota (8192) has been exceeded while reading XML data的解决办法
在web.config中,bindings节点下,对应的服务名称中,原本可能是自动折叠的“/>”,需要改成手动折叠的</binding>,然后在中间加上<readerQuota ...
随机推荐
- 第三百零五节,Django框架,Views(视图函数),也就是逻辑处理函数里的各种方法与属性
Django框架,Views(视图函数),也就是逻辑处理函数里的各种方法与属性 Views(视图函数)逻辑处理,最终是围绕着两个对象实现的 http请求中产生两个核心对象: http请求:HttpRe ...
- linux安装ant
1.从http://ant.apache.org 上下载tar.gz版ant 2.复制到/usr下 3.tar -vxzf apahce-ant-1.9.2-bin.tar.gz 解压 4.chow ...
- VS2010属性表的建立与灵活运用
问题引入:在VS2010当中,进行opencv.QT等的编程时,总是需要配置很多属性还有依赖项等,为了减少每次都重复配置属性的工作量,现在可以运行属性表这个东西来简化配置.opencv也可以这样建立使 ...
- 一个简单的Golang实现的HTTP Proxy
http://blog.csdn.net/michael__li/article/details/53941312
- Effective C++ Item 15 Provide access to raw resources in resource-managing classes
In last two item, I talk about resource-managing using RAII, now comes to the practical part. Often, ...
- Windows7 64bits下安装TensorFlow CPU版本(图文详解)
不多说,直接上干货! Installing TensorFlow on Windows的官网 https://www.tensorflow.org/install/install_windows 首先 ...
- java.lang.OutOfMemoryError 错误分类
java.lang.OutOfMemoryError: Java heap space原因:Heap内存溢出,意味着Young和Old generation的内存不够.解决:调整java启动参数 -X ...
- java中Date的使用情况
在开发中常使用情况. 1.将String转为date 例如"201604131630" //设置日期格式 public SimpleDateFormat sdf = new Si ...
- 【RF库Collections测试】Dictionaries Should Be Equal
Name:Dictionaries Should Be EqualSource:Collections <test library>Arguments:[ dict1 | dict2 | ...
- WebSphere和IHS的安装
环境:CentOS6.5, IP :192.168.0.91 hostname: IHS 1.下载Installation Manage安装包 URL:http://www.ibm.com/devel ...