zoukankan
html css js c++ java
字符串搜索的Sunday算法
public
class
SUNDAY
{
public
SUNDAY()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
public
int
QfindChr(
string
str,
string
Sfind)
{
int
str_length
=
0
;
int
fin_length
=
0
;
int
find_count
=
0
;
int
start
=
0
;
int
moveNum
=
0
;
if
(str.Length
<
Sfind.Length)
{
return
find_count;
}
str_length
=
str.Length;
fin_length
=
Sfind.Length;
while
(start
+
fin_length
<=
str_length)
{
moveNum
++
;
bool
isfind
=
false
;
//
是否在这次移动中找到
string
s_temp
=
str.Substring(start, fin_length);
if
(s_temp
==
Sfind)
{ find_count
++
; start
=
start
+
fin_length; isfind
=
true
; }
if
(isfind
==
false
)
//
如果没找到计算下次移动位置
{
int
forwardPos
=
QfindPos(str, Sfind, start, fin_length);
start
=
forwardPos;
}
}
return
find_count;
}
//
找字符在字符串(不算最后一个字符)的位置(倒数)
//
没找到返回fin_length,找到返回位置
/**/
///
<summary>
///
找字符在字符串(不算最后一个字符)的位置(倒数);没找到返回str.length,找到返回位置
///
</summary>
///
<param name="str"></param>
///
<param name="find"></param>
///
<param name="pos"></param>
///
<param name="fin_length"></param>
///
<returns></returns>
public
int
QfindPos(
string
str,
string
find,
int
pos,
int
fin_length)
{
int
returnPos
=
str.Length;
char
[] Schr
=
str.ToCharArray();
char
[] Sfin
=
find.ToCharArray();
if
((pos
+
fin_length)
<
str.Length)
{
char
chrFind
=
Schr[pos
+
fin_length];
//
要找的字符
if
(fin_length
>=
1
)
{
if
(find.LastIndexOf(chrFind)
>
-
1
)
{
returnPos
=
pos
+
fin_length
-
find.LastIndexOf(chrFind);
}
else
{
returnPos
=
pos
+
fin_length
+
1
;
}
}
}
return
returnPos;
}
}
查看全文
相关阅读:
Sqlserver根据条件去除重复数据并且留下的是最大值数据
C# Linq及Lamda表达式实战应用之 GroupBy 分组统计
MVVM模式WPF的ComboBox数据绑定,使用Dictionary作为数据源
C# System.Timers.Timer定时器的使用和定时自动清理内存应用
SQL优化策略
只要不放弃,总有出头之路
2 Python基础
4 动态库和静态库
1 VS常用快捷键
2 C语言环境、编译
原文地址:https://www.cnblogs.com/Safe3/p/1409011.html
最新文章
Apache(web服务器)与Tomcat(应用服务器)搭建集群
hexo更改主题
github上传本地项目代码
windows下安装hexo和生成博客
JS函数的三种方式
选项卡小案例
MySql注释的写法
织梦dedecms是什么?
MySQL连接使用
ubuntu安装mysql数据库方法
热门文章
display属性
WPF的Image控件图片不能显示出来的问题探究
SqlServer给一个表增加多个字段语法
关于C#中Timer定时器的重入问题解决方法(也适用于多线程)
温故而知新:什么是wcf
FTP文件上传以及获取ftp配置帮助类
文档和视频文件格式的后缀名验证以及图片的真实验证帮助类
文档转换为pdf格式帮助类
DES加密与解密MD5加密帮助类
数据加密实战之记住密码、自动登录和加密保存数据运用DES和MD5混合使用
Copyright © 2011-2022 走看看