在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的更多相关文章

  1. 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 问题:调用第三 ...

  2. 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 ...

  3. String.length()和String.getBytes().length

    1.字符与字节 抛出如下代码: public static void main(String[] args) { String str = "活出自己范儿"; System.out ...

  4. 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 ...

  5. java - 数组与String的length方法问题

    java数组没有length()方法,java数组有length属性: String有length()方法.

  6. String的length()和Array的length

    String是个final修饰的最终类,不能被继承,String中属性都设置为private,方法为public,并不提供set方法,想要获得字符串的长度必须调用length()方法这个长度是确定的, ...

  7. string.trim().length()的用法

    public class Test{ public static void main(String args[]){ String data = " a bc "; //调用str ...

  8. String 对象-->length 属性

    1.定义和用法 length 属性返回字符串的长度(字符数). 语法: string.length 注意:根据各国字符长度计算长度 举例: var str = 'abner pan' console. ...

  9. 调用WebServiceWebService提示The maximum string content length quota (8192) has been exceeded while reading XML data的解决办法

    在web.config中,bindings节点下,对应的服务名称中,原本可能是自动折叠的“/>”,需要改成手动折叠的</binding>,然后在中间加上<readerQuota ...

随机推荐

  1. 【转】BMP图像文件格式

    5.1  BMP图像文件格式 BMP图像文件格式是游戏中常用的图像资源文件格式,BMP图像文件起源早,程序员对BMP都比较熟悉,再加上BMP格式简单,读取和写入非常容易实现,所以无论Windows的还 ...

  2. java_Observer Design Pattern

    摘自: http://www.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html Creating Your Own Event, Source ...

  3. R语言低级绘图函数-arrows

    arrows 函数用来在一张图表上添加箭头,只需要分别指定起始坐标和终止坐标,就可以添加箭头了,还可以通过一些属性对箭头的形状,大小进行调整 基本用法: xo, yo 指定起始点的x和y坐标,x1, ...

  4. hadoop中文官网

    http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html

  5. 10046事件sql_trace跟踪

    查看 sql 执行计划的方法有许多种, 10046 事件就是其中的一种. 与其他查看 sql 执行计划不同, 当我们遇到比较复杂的 sql 语句, 我们可以通过 10046 跟踪 sql 得到执行计划 ...

  6. jQuery动态生成Bootstrap表格

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  7. PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例

    前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...

  8. catch(…) vs catch(CException *)?

    转自:https://stackoverflow.com/questions/7412185/what-is-the-difference-between-catch-vs-catchcexcepti ...

  9. Shell 文本处理工具

    转载自:http://www.cnblogs.com/wish123/p/5540210.html Linux下使用Shell处理文本时最常用的工具: find.grep.xargs.sort.uni ...

  10. 【java】java设计模式(5):原型模式(Prototype)

    原型模式虽然是创建型的模式,但是与工程模式没有关系,从名字即可看出,该模式的思想就是将一个对象作为原型,对其进行复制.克隆,产生一个和原对象类似的新对象.本小结会通过对象的复制,进行讲解.在Java中 ...