16,552
社区成员
发帖
与我相关
我的任务
分享
CREATE SCHEMA [String] AUTHORIZATION [dbo]
-- ===========================================================
-- Author: LzmTW
-- Create date: 20080111
-- Description: 返回一个字符串,它包含一个没有前导空格 (LTrim)、尾随空格 (RTrim)
-- 或既没有前导空格也没有尾随空格 (Trim)的指定字符串的副本。
-- ===========================================================
CREATE FUNCTION [String].[Trim]
(
@Value nvarchar(max)
)
RETURNS nvarchar(max)
AS
BEGIN
IF @Value IS NULL
RETURN NULL
DECLARE @Result nvarchar(max)
SET @Result = LTRIM(RTRIM(@Value))
RETURN @Result
END
-- ================================================================================
-- Author:LzmTW
-- Create date:20080110
-- Description:返回子字符串在给定字符串中的匹配索引的集合(仅取最紧凑的匹配项)
-- @IsVagueMode:是否在使用模糊查询方式 0否,1是
-- Note:模糊查询中对单%无效,即Pattern = N'%%%'
-- ================================================================================
CREATE FUNCTION [String].[IndexArray]
(
@Value nvarchar(max)
,@Search nvarchar(max)
,@IsVagueMode bit = 0
)
RETURNS
@Table TABLE
(
[ID] int identity(1,1) PRIMARY KEY
,[Index] int
,[Catch] nvarchar(max)
,[Len] int
)
AS
BEGIN
IF @Value IS NULL OR @Search IS NULL OR @IsVagueMode IS NULL
RETURN
DECLARE
@String nvarchar(max)
,@Pattern nvarchar(max)
,@Index int
,@CurrentIndex int
,@Catch nvarchar(max)
,@Tmp nvarchar(max)
,@TmpLen int
,@TmpIndex int
SET @String = @Value
/* Charindex交付Patindex处理,合并处理,不含取Catch
IF @IsVagueMode = 0
BEGIN
SET @Pattern = REPLACE(@Search, N'%', QUOTENAME(N'%'))
SET @Pattern = REPLACE(@Pattern, N'_', QUOTENAME(N'_'))
SET @Pattern = N'%' + @Pattern + N'%'
END
ELSE
SET @Pattern = @Search
SET @Index = PATINDEX(@Pattern, @String)
SET @CurrentIndex = 0
WHILE @Index > 0
BEGIN
SET @CurrentIndex = @CurrentIndex + @Index
INSERT INTO @Table([Index]) VALUES (@CurrentIndex)
SET @String = STUFF( @String, 1, @Index, N'')
SET @Index = PATINDEX(@Pattern, @String)
END
合并处理结束*/
/*以下为分别处理*/
IF @IsVagueMode = 0
BEGIN
SET @Pattern = @Search
SET @Index = CHARINDEX(@Pattern, @String)
SET @CurrentIndex = 0
SET @Catch = @Pattern
WHILE @Index > 0
BEGIN
INSERT INTO @Table VALUES (@Index, @Catch, [String].[Len](@Catch))
SET @CurrentIndex = @Index + 1
SET @Index = CHARINDEX(@Pattern, @String, @CurrentIndex)
END
END
ELSE
BEGIN
SET @Pattern = @Search
SET @Index = PATINDEX(@Pattern, @String)
SET @CurrentIndex = 0
WHILE @Index > 0
BEGIN
SET @CurrentIndex = @CurrentIndex + @Index
SET @Tmp = @String
SET @TmpLen = LEN(@Tmp)
SET @TmpIndex = 0
WHILE PATINDEX(@Pattern, @Tmp) > 0 AND @TmpLen >= @TmpIndex
BEGIN
SET @Catch = @Tmp
SET @TmpIndex = @TmpIndex + 1
SET @Tmp = LEFT(@Tmp, @TmpLen - @TmpIndex)
END
SET @Tmp = @Catch
SET @TmpLen = LEN(@Tmp)
SET @TmpIndex = 0
WHILE PATINDEX(@Pattern, @Tmp) > 0 AND @TmpLen >= @TmpIndex
BEGIN
SET @Catch = @Tmp
SET @TmpIndex = @TmpIndex + 1
SET @Tmp = RIGHT(@Tmp, @TmpLen - @TmpIndex)
END
IF SUBSTRING(@Value, @CurrentIndex, [String].[Len](@Catch)) = @Catch
INSERT INTO @Table VALUES (@CurrentIndex, @Catch, [String].[Len](@Catch))
SET @String = STUFF( @String, 1, @Index, N'')
SET @Index = PATINDEX(@Pattern, @String)
END
END
/*分别处理结束*/
RETURN
END
DECLARE @Info nvarchar(max)
SET @Info = N'
<td><a rel="mz" href=''http://www.csdn.net/''>首页</a></td>
<td><a rel="mz" href=''http://news.csdn.net/''>新闻</a></td>
<td><a rel="mz" href=''http://bbs.csdn.net/''>论坛</a></td>
<td><a rel="mz" href=''http://groups.csdn.net/''>群组</a></td>
<td><a rel="mz" href=''http://blog.csdn.net/''>Blog</a></td>
<td><a rel="mz" href=''http://dev.csdn.net/''>文档</a></td>
<td><a rel="mz" href=''http://download.csdn.net/''>下载</a></td>
<td><a rel="mz" href=''http://book.csdn.net/''>读书</a></td>
<td><a rel="mz" href=''http://tag.csdn.net/''>Tag</a></td>
<td><a rel="mz" href=''http://wz.csdn.net/''>网摘</a></td>
<td><a rel="mz" href=''http://search.csdn.net/''>搜索</a></td>
<td><a rel="mz" href=''http://gforge.osdn.net.cn/''>开源</a></td>
<td><a rel="mz" href=''http://faq.csdn.net/''>FAQ</a></td>
<td><a rel="mz" href=''http://www.dearbook.com.cn/''>第二书店</a></td>
<td><a rel="mz" href=''http://www.broadview.com.cn/''>博文视点</a></td>
<td><a rel="mz" href=''http://www.programmer.com.cn/''>程序员</a></td>
'
SELECT
[Title] = CAST(REPLACE(REPLACE(b.[Catch], N'>', N''), N'</a', N'') AS nvarchar(4))
,[Url] = CAST(a.[Catch] AS varchar(40))
FROM [LzmTW].[String].[IndexArray] (
@Info
,N'%http://%/%'
,1) a
INNER JOIN
[LzmTW].[String].[IndexArray] (
@Info
,N'%>%</a>%'
,1) b
ON a.ID = b.ID
Title Url
----- ----------------------------------------
首页 http://www.csdn.net/
新闻 http://news.csdn.net/
论坛 http://bbs.csdn.net/
群组 http://groups.csdn.net/
Blog http://blog.csdn.net/
文档 http://dev.csdn.net/
下载 http://download.csdn.net/
读书 http://book.csdn.net/
Tag http://tag.csdn.net/
网摘 http://wz.csdn.net/
搜索 http://search.csdn.net/
开源 http://gforge.osdn.net.cn/
FAQ http://faq.csdn.net/
第二书店 http://www.dearbook.com.cn/
博文视点 http://www.broadview.com.cn/
程序员 http://www.programmer.com.cn/
(16 行受影响)
DECLARE @Info nvarchar(max)
SET @Info = N'
√ 也试试数据项的分拆与合并 [MS-SQL Server][基础类] 100 lzmtw
01-06 23:39 57 lzmtw
01-09 15:30 管理
√ 矢集快照(想法记存) [精] [.NET技术][VB.NET] 0 lzmtw
12-17 12:04 29 waxxx
01-08 14:09 管理
√ 创建矢集快照数据库基本要素 [精] [.NET技术][VB.NET] 200 lzmtw
01-05 17:50 42 aptech_zhang
01-08 13:24 管理
√ 存储过程中如何创建别库的自定义函数 [MS-SQL Server][基础类] 100 lzmtw
12-06 10:32 20 fcuandy
01-05 21:49 管理
√ 人算真不如天算,恼努,散三百分 [扩充话题][灌水乐园] 300 lzmtw
12-31 00:14 144 liudng
01-05 10:19 管理
√ 国庆快乐 [.NET技术][非技术区] 200 lzmtw
09-28 08:35 65 sungger
01-03 21:44 管理
√ 局域网内外数据交换的前端安全防范(晒晒) [.NET技术][非技术区] 300 lzmtw
01-03 15:14 45 fairyZ1231
01-03 18:04 管理
√ 对查询增加序列号的办法(晒晒,是否方便呢) [MS-SQL Server][基础类] 100 lzmtw
12-29 15:17 35 changjiangzhibin
01-03 16:31 管理
√ 考勤之延伸:SQLServer2005 农历日期 [精] [.NET技术][VB.NET] 300 lzmtw
12-24 15:11 66 LikeCode
01-02 20:33 管理
√ 快讯:中国个人所得税起征点有望上调至二千元 [扩充话题][灌水乐园] 100 lzmtw
12-23 12:06 133 yzl20080101
01-01 10:07 管理
√ 胡说乱语(一) [.NET技术][VB.NET] 0 lzmtw
11-19 14:34 25 lzmtw
12-31 00:02 管理
√ SQLServer2005中如何设计个税计算 [MS-SQL Server][基础类] 300 lzmtw
12-06 17:18 57 lzmtw
12-29 20:19 管理
√ HOW TO:网络适配器基本信息的设置 [精] [.NET技术][VB.NET] 300 lzmtw
11-01 16:28 65 lian_feixian
12-29 11:03 管理
√ 能取到存储过程理的第二个数据集吗? [MS-SQL Server][基础类] 100 lzmtw
12-28 23:46 22 lzmtw
12-29 01:12 管理
√ 考勤之延伸:SQLServer2005 年工作日期 [.NET技术][VB.NET] 100 lzmtw
12-27 14:33 29 gamewater
12-28 15:08 管理
√ 矢集快照场景应用一:考勤(二) [.NET技术][VB.NET] 0 lzmtw
12-20 14:59 7 lzmtw
12-24 20:09 管理
√ 矢集快照场景应用二:中国法定假日 [.NET技术][VB.NET] 0 lzmtw
12-20 21:53 34 lzmtw
12-21 21:16 管理
√ 矢集快照场景应用一:考勤 [.NET技术][VB.NET] 0 lzmtw
12-18 17:05 42 lzmtw
12-20 13:15 管理
√ 好久没写代码了,写个复数类试试看 [精] [.NET技术][VB.NET] 300 lzmtw
10-17 21:12 128 lzmtw
12-17 21:53 管理
√ 中国数字(欢迎验错) [MS-SQL Server][基础类] 100 lzmtw
12-12 18:42 47 kk19840210
12-14 12:46 管理
√ 中国数字 [.NET技术][VB.NET] 0 lzmtw
12-10 18:00 19 lzmtw
12-11 19:28 管理
√ 行政区划代码数据分析 [MS-SQL Server][基础类] 100 lzmtw
12-09 14:54 49 lzmtw
12-11 10:37 管理
√ Microsoft Visual Studio International Pack 1.0 Beta1(2007/11/28) [.NET技术][VB.NET] 0 lzmtw
12-01 17:18 16 lzmtw
12-06 13:21 管理
√ HOW TO:网络适配器基本信息的设置(二) [精] [.NET技术][VB.NET] 0 lzmtw
11-26 14:53 41 zanfeng
11-30 21:42 管理
√ 你知道吗 [.NET技术][VB.NET] 0 lzmtw
11-14 13:58 26 lzmtw
11-19 09:42 管理
√ 关于配置文件 [.NET技术][VB.NET] 0 lzmtw
11-14 12:38 1 lzmtw
11-14 12:40 管理
√ 正则表达式集贴 [.NET技术][VB.NET] 0 lzmtw
11-03 20:56 15 dracula1133
11-13 20:27 管理
√ 试试做做这道题,可以测试自己的综合能力 [.NET技术][VB.NET] 200 lzmtw
11-03 16:28 13 lzmtw
11-03 17:45 管理
√ 招集方案:如何在CSDN论坛贴子画圆 [.NET技术][非技术区] 300 lzmtw
10-22 12:34 47 wesnow
10-30 15:10 管理
√ 方圆问题程序求法 [.NET技术][VB.NET] 300 lzmtw
10-29 14:04 19 vwxyzh
10-30 09:08 管理
√ 没意思的,不用进来 [.NET技术][VB.NET] 0 lzmtw
10-20 22:53 25 lzmtw
10-23 09:21 管理
√ Net.ApiHook [.NET技术][VB.NET] 20 lzmtw
10-20 11:51 9 lzmtw
10-20 13:22 管理
'
DECLARE
@Pattern nvarchar(20)
SET @Pattern = N'% % lzmtw%'
SELECT
Point = CAST([String].[Trim](REPLACE([Catch], 'lzmtw', '')) AS smallint)
FROM [String].[FindAll] (
@Info
,@Pattern
,1)
Point
------
100
57
0
200
100
300
200
300
100
300
100
0
25
300
57
300
100
22
100
0
7
0
34
0
42
300
128
100
0
19
100
49
0
16
0
0
26
0
1
0
200
13
300
300
0
25
20
9
(48 行受影响)