关于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 ...
随机推荐
- C++之程序时间统计类实现
/********** TimeCounter.h huangsy13@gmail.com **********/ #ifndef TIMECOUNTER #define TIMECOUNTER #i ...
- python 向qq邮箱发邮件
#coding:utf-8 ''' Created on 2017-1-12 @author: xiaochun ''' import smtplib from email.mime.text imp ...
- ffmpeg 源码分析
http://blog.csdn.net/liuhongxiangm/article/details/8824761 https://code.google.com/p/ffmpegsource/is ...
- linux下简单好用的端口映射转发工具rinetd 转
linux下简单好用的工具rinetd,实现端口映射/转发/重定向 官网地址http://www.boutell.com/rinetd 软件下载 wget http://www.boutell.com ...
- 世界上最痛苦的事就是去改别人的bug!!!!
世界上最痛苦的事就是去改别人的bug!!!!
- Ajax分页(MVC下)(附源码,前后台)
网上找的一个分页js,自己改了改.. 前台页面 @{ ViewBag.Title = "Index"; } <h1>分页方法封装</h1> <scri ...
- 函数preg_replace()与str_replace()
如截图,preg_replace()的用法 <?php $str="as2223adfsf0s4df0sdfsdf"; echo preg_replace("/0/ ...
- C++ string(转)
C++中string是标准库中一种容器,相当于保存元素类型为char的vector容器(自己理解),这个类提供了相当丰富的函数来完成对字符串操作,以及与C风格字符串之间转换,下面是对string一些总 ...
- ChemDraw Std 14如何标记同位素
ChemDraw软件是一款专业高效的化学绘图工具,能够绘制各种复杂的结构方程式,在基础化学.有机化学.材料化学等领域得到广泛应用.而ChemDraw Std 14 作为ChemDraw 的最新版本,增 ...
- Python图像处理库PIL的ImageSequence模块介绍
ImageSequence模块包括了一个wrapper类,它能够让用户迭代訪问图形序列中每一帧图像. 一.ImageSequence模块的函数 1. Iterator 定义:ImageSequenc ...