Split()函数

最近遇到一个有趣的问题关于使用Split函数 ,该函数能够根据传递的参数拆分,并返回一个string的数组。

贴出一个奇怪的例子

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace voucher.AutoCreatXml.Code
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string str = "887766555444333";

            int number1 = str.Split(‘8‘).Length-1;
            int a = 8;
            int number2 = str.Split(Convert.ToChar(a)).Length - 1;

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","alert(‘number1:"+number1+"***number2:"+number2+"‘)",true);
        }
    }
}

输出的结果
难道Convert.ToChar()不能转换?赶紧调试了一下  ,发现

难怪number1和Number2的值不一样。仔细一想原来是int number1 = str.Split(‘8‘).Length-1;  这个8 是个char字符,然而int a = 8;int number2 = str.Split(Convert.ToChar(a)).Length - 1; 这个是将int类型的8转化为字符串,当然不一样了  ‘8‘ 是char字符串unicode码

https://msdn.microsoft.com/zh-cn/library/x9h8tsay.aspx有关char类型

时间: 2024-07-29 23:22:35

Split()函数的相关文章

split函数

Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list)os.path.split():按照路径将文件名和路径分割开 一.函数说明1.split()函数 语法:str.split(str="",num=string.count(str))[n] 参数说明:str:   表示为分隔符,默认为空格,但是不能为空('').若字符串中没有分隔符,则把整个字符串作为列表的

python中join和split函数

一个是分割,一个是连接. 惯例,先看内部帮助文档 Help on method_descriptor: join(...) S.join(iterable) -> string Return a string which is the concatenation of the strings in the iterable. The separator between elements is S. (END) 将可迭代对象(包含的应该是str类型的,不然会报错)连接起来, 返回值是str,用法如

perl:split函数用法

本文和大家重点讨论一下Perl split函数的用法,Perl中的一个非常有用的函数是Perl split函数-把字符串进行分割并把分割后的结果放入数组中.这个Perl split函数使用规则表达式(RE),如果未特定则工作在$_变量上. Perl split函数 Perl中的一个非常有用的函数是Perl split函数-把字符串进行分割并把分割后的结果放入数组中.这个Perl split函数使用规则表达式(RE),如果未特定则工作在$_变量上. Perl split函数可以这样使用: $inf

SQL中实现SPLIT函数几种方法

例1 代码如下 复制代码 create function f_split(@SourceSql varchar(8000),@StrSeprate varchar(10))returns @temp table(a varchar(100))--实现split功能 的函数--date :2003-10-14as begin declare @i int set @SourceSql=rtrim(ltrim(@SourceSql)) set @i=charindex(@StrSeprate,@So

awk中split函数的用法

The awk function split(s,a,sep) splits a string s into an awk array a using the delimiter sep. time=12:34:56 echo $time | awk '{split($0,a,":" ); print a[1]}' 12   echo $time | awk '{split($0,a,":" ); print a[3]}' 34   echo $time | awk

python 中join()函数strip() 函数和 split() 函数的详解及实例

1.join()函数 Python中有join()和os.path.join()两个函数,具体作用如下: join():                连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 语法:  'sep'.join(seq) 参数说明sep:分隔符.可以为空seq:要连接的元素序列.字符串.元组.字典上面的语法即:以sep作为分隔符,将seq所有的元素合并成一个新的字符串 返回值:返回一个以分隔符sep连接各个元素后生成的字符串 os.p

Python中的split()函数的使用方法

函数:split() Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list)os.path.split():按照路径将文件名和路径分割开 一.函数说明1.split()函数语法:str.split(str="",num=string.count(str))[n] 参数说明:str:   表示为分隔符,默认为空格,但是不能为空('').若字符串中没有分隔符,则把

oracle实现split函数功能

转载: http://blog.csdn.net/jojo52013145/article/details/6758279在实际的应用中,为了让PL/SQL 函数返回数据的多个行,必须通过返回一个 REF CURSOR 或一个数据集合来完成.REF CURSOR 的这种情况局限于可以从查询中选择的数据,而整个集合在可以返回前,必须进行具体化. 9i 通过引入的管道化表函数纠正了后一种情况.表函数是返回整个行的集(通常作为一个集合)的函数,可以直接从 SQL 语句中进行查询,就好像它是一个真正的数

Java——String.split()函数

在java doc里有 String[] java.lang.String.split(String regex) Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Tra

Delphi中怎样将字符串按给定字符分隔(类似split函数的功能)

Delphi中怎样将字符串按给定字符分隔(类似split函数的功能) 分类:            Delphi2007-05-16 11:094911人阅读评论(2)收藏举报 delphiintegerstringbutton文本编辑function 今天偶尔要做的Delphi程序,其中涉及到了字符串处理,里面有一个功能类似于VB里的split()函数的功能,于是查了很久才查到些资料,现将这些资料整理一下,方便大家. 首先是一个网友自己编的函数.实现了和split()函数的功能. unit U