您的位置:首页 > 其它

字符串截取的两种方式

2011-11-09 15:51 162 查看
字符串的截取,在此提供两种方式:一种使用C#语言的split()函数;另一种使用存储过程来实现。

  字符串的截取,在此提供两种方式:

  一种使用C#语言的split()函数

  另一种使用存储过程来实现

  (一)使用split()函数 

string str="1/2/3/444/3333/222/5555/";

  string[] arr_str;

  arr_str=str.split('/')

  for(int i=0;i

  {

  Response.Write(strData[i]+"

");

  }
  (二)使用存储过程

  --将字符串分割后存放在临时表中,然后将数据返回! 

ALTER procedure [dbo].[ZXKS_KS_getjzxx]

  @jzbh int

  as
  --创建临时表,用来保存试题编号

create table temp_table

  (

  id int IDENTITY(1,1) primary key,

  stid int

  )

  DECLARE @object_id nvarchar(500)

  DECLARE @i INT

  DECLARE @len INT

  Declare @string nvarchar(500)
  --根据卷子编号获取试题编号字符串

set @string =(select stid from ks_jzxx where jzid=@jzbh)
  --将试题编号字符串进行拆分,然后放在临时表中

IF (@string IS NULL) OR (LTRIM(@string) = '')

  RETURN

  WHILE CHARINDEX('/',@string) > 0

  BEGIN

  SET @len = LEN(@string)

  SET @i = CHARINDEX('/', @string)

  SET @object_id = LEFT(@string, @i-1)

  INSERT INTO temp_table (stid) VALUES (@object_id)--少做修改,改成需要的sql语句即可

  SET @string = RIGHT(@string, @len - @i)

  END

  select * from temp_table
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: