/* 中文处理工具函数
--- 空格 ---
string GBspace(string) --------- 每个中文字之间加空格
string GBunspace(string) ------- 每个中文字之间的空格清除
string clear_space(string) ------- 用来清除多余的空格
--- 转换 ---
string GBcase(string,offset) --- 将字符串内的中英文字转换大小写
offset : "upper" - 字符串全转为大写 (strtoupper)
"lower" - 字符串全转为小写 (strtolower)
"ucwords" - 将字符串每个字第一个字母改大写 (ucwords)
"ucfirst" - 将字符串第一个字母改大写 (ucfirst)
string GBrev(string) ----------- 颠倒字符串
--- 文字检查 ---
int GB_check(string) ----------- 检查字符串内是否有 GB 字,有会返回 true,
否则会返回false
int GB_all(string) ------------- 检查字符串内所有字是否有 GB 字,是会返回 true,
否则会返回false
int GB_non(string) ------------- 检查字符串内所有字并不是 GB 字,是会返回 true,
否则会返回false
int GBlen(string) -------------- 返回字符串长度(中文字只计一字母)
--- 查找、取代、提取 ---
int/array GBpos(haystack,needle,[offset]) ---- 查找字符串 (strpos)
offset : 留空 - 查找第一个出现的位置
int - 由该位置搜索出现的第一个位置
"r" - 查找最后一次出现的位置 (strrpos)
"a" - 将所有查找到的字储存为数组(返回 array)
string GB_replace(needle,str,haystack) -- 查找与取代字符串 (str_replace)
string GB_replace_i(needle,str_f,str_b,haystack) -- 不检查大小写查找与取代字符串
needle - 查找字母
str - 取代字母 ( str_f - 该字母前, str_b 该字母后)
haystack - 字符串
string GBsubstr(string,start,[length]) -- 从string提取出由开始到结尾或长度
length的字符串。
中文字只计一字母,可使用正负数。
string GBstrnear(string,length) -- 从 string提取最接近 length的字符串。
length 中 中文字计2个字母。
--- 注意 ---
如使用由 Form 返回的字符串前,请先替字符串经过 stripslashes() 处理,除去多余的 \ 。
用法:在原 PHP 代码内加上:
include ("GB.inc");
即可使用以上工具函数。
*/
function GBlen($string) {
$l = strlen($string);
$ptr = 0;
$a = 0;
while ($a $ch = substr($string,$a,1);
$ch2 = substr($string,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
$ptr++;
$a += 2;
} else {
$ptr++;
$a++;
} // END IF
} // END WHILE
return $ptr;
}
function GBsubstr($string,$start,$length) {
if (!is_int($length) && $length != "") {
return "错误:length 值错误(必须为数值)。
";
} elseif ($length == "0") {
return "";
} else {
$l = strlen($string);
$a = 0;
$ptr = 0;
$str_list = array();
$str_list2 = array();
while ($a $ch = substr($string,$a,1);
$ch2 = substr($string,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
$str_list[$ptr] = $a;
$str_list2[$ptr] = $a+1;
$ptr++;
$a += 2;
} else {
$str_list[$ptr] = $a;
$str_list2[$ptr] = $a;
$ptr++;
$a++;
} // END IF
} // END WHILE
if ($start > $ptr || -$start > $ptr) {
return;
} elseif ($length == "") {
if ($start >= 0) { // (text,+)
return substr($string,$str_list[$start]);
} else { // (test,-)
return substr($string,$str_list[$ptr + $start]);
}
} else {
if ($length > 0) { // $length > 0
if ($start >= 0) { // (text,+,+)
if (($start + $length) >= count($str_list2)) {
return substr($string,$str_list[$start]);
} else { //(text,+,+)
$end = $str_list2[$start + ($length - 1)] - $str_list[$start] +1;
return substr($string,$str_list[$start],$end);
}
} else { // (text ,-,+)
$start = $ptr + $start;
if (($start + $length) >= count($str_list2)) {
return substr($string,$str_list[$start]);
} else {
$end = $str_list2[$start + ($length - 1)] - $str_list[$start] +1;
return substr($string,$str_list[$start],$end);
}
}
} else { // $length $end = strlen($string) - $str_list[$ptr+$length];
if ($start >= 0) { // (text,+,-) {
return substr($string,$str_list[$start],-$end);
} else { //(text,-,-)
$start = $ptr + $start;
return substr($string,$str_list[$start],-$end);
}
} // END OF LENGTH > /
}
} // END IF
}
function GB_replace($needle,$string,$haystack) {
$l = strlen($haystack);
$l2 = strlen($needle);
$l3 = strlen($string);
$news = "";
$skip = 0;
$a = 0;
while ($a $ch = substr($haystack,$a,1);
$ch2 = substr($haystack,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
if (substr($haystack,$a,$l2) == $needle) {
$news .= $string;
$a += $l2;
} else {
$news .= $ch.$ch2;
$a += 2;
}
} else {
if (substr($haystack,$a,$l2) == $needle) {
$news .= $string;
$a += $l2;
} else {
$news .= $ch;
$a++;
}
} // END IF
} // END WHILE
return $news;
}
function GB_replace_i($needle,$str_f,$str_b,$haystack) {
$l = strlen($haystack);
$l2 = strlen($needle);
$l3 = strlen($string);
$news = "";
$skip = 0;
$a = 0;
while ($a $ch = substr($haystack,$a,1);
$ch2 = substr($haystack,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
if (GBcase(substr($haystack,$a,$l2),"lower") == GBcase($needle,"lower")) {
$news .= $str_f . substr($haystack,$a,$l2) . $str_b;
$a += $l2;
} else {
$news .= $ch.$ch2;
$a += 2;
}
} else {
if (GBcase(substr($haystack,$a,$l2),"lower") == GBcase($needle,"lower")) {
$news .= $str_f . substr($haystack,$a,$l2) . $str_b;
$a += $l2;
} else {
$news .= $ch;
$a++;
}
} // END IF
} // END WHILE
return $news;
}
function GBpos($haystack,$needle,$offset) {
if (!is_int($offset)) {
$offset = strtolower($offset);
if ($offset != "" && $offset != "r" && $offset != "a") {
return "错误:offset 值错误。
";
}
}
$l = strlen($haystack);
$l2 = strlen($needle);
$found = false;
$w = 0; // WORD
$a = 0; // START
if ($offset == "" || $offset == "r") {
$atleast = 0;
$value = false;
} elseif ($offset == "a") {
$value = array();
$atleast = 0;
} else {
$value = false;
$atleast = $offset;
}
while ($a $ch = substr($haystack,$a,1);
$ch2 = substr($haystack,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40") && $skip == 0) {
if (substr($haystack,$a,$l2) == $needle) {
if ($offset == "r") {
$found = true;
$value = $w;
} elseif ($offset == "a") {
$found = true;
$value[] = $w;
} elseif (!$value) {
if ($w >= $atleast) {
$found = true;
$value = $w;
}
}
}
$a += 2;
} else {
if (substr($haystack,$a,$l2) == $needle) {
if ($offset == "r") {
$found = true;
$value = $w;
} elseif ($offset == "a") {
$found = true;
$value[] = $w;
} elseif (!$value) {
if ($w >= $atleast) {
$found = true;
$value = $w;
}
}
}
$a++;
}
$w++;
} // END OF WHILE
if ($found) {
return $value;
} else {
return $false;
}
// } // END OF WHILE
}
function GBrev($text) {
$news = "";
$l = strlen($text);
$GB = 0;
$a = 0;
while ($a $ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40") && $skip == 0) {
$a += 2;
$news = $ch . $ch2 . $news;
} else {
$news = $ch . $news;
$a++;
}
}
return $news;
}
function GB_check($text) {
$l = strlen($text);
$a = 0;
while ($a $ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
return true;
} else {
return false;
}
}
}
function GB_all ($text) {
$l = strlen($text);
$all = 1;
$a = 0;
while ($a $ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
$a += 2;
} else {
$a++;
$all = 0;
}
}
if ($all == 1) {
return true;
} else {
return false;
}
}
function GB_non ($text) {
$l = strlen($text);
$all = 1;
$a = 0;
while ($a $ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
$a += 2;
$all = 0;
} else {
$a++;
}
}
if ($all == 1) {
return true;
} else {
return false;
}
}
function GBcase ($text,$case) {
$case = strtolower($case);
if ($case != "upper" && $case != "lower" && $case != "ucwords" && $case != "ucfirst") {
return "函数用法错误。 $case";
} else {
$ucfirst = 0;
$ucwords = 0;
$news = "";
$l = strlen($text);
$GB = 0;
$english = 0;
$a = 0;
while ($a
$ch = substr($text,$a,1);
if ($GB == 0 && ord($ch) >= HexDec("0x81")) {
$GB = 1;
$english = 0;
$news .= $ch;
$ucwords = 0;
} elseif ($GB == 1 && ord($ch) >= HexDec("0x40") && $english == 0) {
$news .= "$ch";
$ucwords = 0;
$GB = 0;
} else {
if ($case == "upper") {
$news .= strtoupper($ch);
} elseif ($case == "lower") {
$news .= strtolower($ch);
} elseif ($case == "ucwords") {
if ($ucwords == 0) {
$news .= strtoupper($ch);
} else {
$news .= strtolower($ch);
}
$ucwords = 1;
} elseif ($case == "ucfirst") {
if ($ucfirst == 0) {
$news .= strtoupper($ch);
$ucfirst = 1;
} else {
$news .= strtolower($ch);
$ucfirst = 1;
}
} else {
$news .= $ch;
}
if ($ch == " " || $ch == "\n") {
$ucwords = 0;
}
$english = 1;
$GB = 0;
}
$a++;
} // END OF while
return $news;
} // end else
}
function GBspace ($text) {
$news = "";
$l = strlen($text);
$GB = 0;
$english = 0;
$a = 0;
while ($a
$ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
if (!($ch == " " && $ch2 == " ")) {
if ($GB == 0) {
if (ord($ch) >= HexDec("0x81")) {
if ($english == 1) {
if ((substr($text,$a-1,1) == " ") || (substr($text,$a-1,1) == "\n")) {
$news .= "$ch";
} else {
$news .= " $ch";
}
$english = 0;
$GB = 1;
} else {
$GB = 1;
$english = 0;
$news .= $ch;
}
} else {
$english = 1;
$GB = 0;
$news .= $ch;
}
} else {
if (ord($ch) >= HexDec("0x40")) {
if ($english == 0) {
if ((substr($text,$a+1,1) == " ")|| (substr($text,$a+1,1) == "\n")) {
$news .= "$ch";
} else {
$news .= "$ch ";
}
} else {
$news .= " $ch";
}
} else {
$english = 1;
$news .= "$ch";
}
$GB = 0;
}
}
$a++;
} // END OF while
// Chk 1 & last is space
$l = strlen($news);
if (substr($news,0,1) == " ") {
$news = substr($news,1);
}
$l = strlen($news);
if (substr($news,$l-1,1) == " ") {
$news = substr($news,0,$l-1);
}
return $news;
}
function GBunspace($text) {
$news = "";
$l = strlen($text);
$a = 0;
$last_space = 1;
while ($a
$ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
$ch3 = substr($text,$a+2,1);
if (($a + 1) == $l ) {
$last_space = 1;
}
if ($ch == " ") {
if ($last_space == 0) {
if (ord($ch2) >= HexDec("0x81") && ord($ch3) >= HexDec("0x40")) {
if ($chi == 0) {
$news .= " ";
$last_space = 1;
}
$chi=1;
} elseif ($ch2 != " ") {
$news .= " ";
$chi = 0;
$last_space = 1;
}
}
} else {
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
$chi = 1;
$a++;
$news .= $ch . $ch2;
$last_space = 0;
} else {
$chi = 0;
$news .= $ch;
$last_space = 0;
}
}
$a++;
}
// Chk 1 & last is space
$l = strlen($news);
if (substr($news,0,1) == " ") {
$news = substr($news,1);
}
$l = strlen($news);
if (substr($news,$l-1,1) == " ") {
$news = substr($news,0,$l-1);
}
return $news;
} // END OF Function
function GBstrnear($text,$length) {
$tex_len = strlen($text);
$a = 0;
$w = "";
while ($a $ch = substr($text,$a,1);
$ch2 = substr($text,$a+1,1);
if (GB_all($ch.$ch2)) {
$w .= $ch.$ch2;
$a=$a+2;
} else {
$w .= $ch;
$a++;
}
if ($a == $length || $a == ($length - 1)) {
$a = $tex_len;
}
}
return $w;
} // END OF FUNCTION
function clear_space($text) {
$t = "";
for ($a=0;$a
$ch2 = substr($text,$a+1,1);
if ($ch == " " && $ch2 == " ") {
} else {
$t .= $ch;
}
}
return $t;
}
?>

Python 中有许多方法可以帮助我们理解代码的内部工作原理,良好的编程习惯,可以使我们的工作事半功倍!例如,我们最终可能会得到看起来很像下图中的代码。虽然不是最糟糕的,但是,我们需要扩展一些事情,例如:load_las_file 函数中的 f 和 d 代表什么?为什么我们要在 clay 函数中检查结果?这些函数需要什么类型?Floats? DataFrames?在本文中,我们将着重讨论如何通过文档、提示输入和正确的变量名称来提高应用程序/脚本的可读性的五个基本技巧。1. Comments我们可

连续分级概率评分(Continuous Ranked Probability Score, CRPS)或“连续概率排位分数”是一个函数或统计量,可以将分布预测与真实值进行比较。机器学习工作流程的一个重要部分是模型评估。这个过程本身可以被认为是常识:将数据分成训练集和测试集,在训练集上训练模型,并使用评分函数评估其在测试集上的性能。评分函数(或度量)是将真实值及其预测映射到一个单一且可比较的值 [1]。例如,对于连续预测可以使用 RMSE、MAE、MAPE 或 R 平方等评分函数。如果预测不是逐点

js是弱类型语言,不能像C#那样使用param关键字来声明形参是一个可变参数。那么js中,如何实现这种可变参数呢?下面本篇文章就来聊聊JavaScript函数可变参数的实现方法,希望对大家有所帮助!

一、前言前几天在Python钻石交流群有个叫【emerson】的粉丝问了一个Python排序的问题,这里拿出来给大家分享下,一起学习下。其实这里【瑜亮老师】、【布达佩斯的永恒】等人讲了很多,只不过对于基础不太好的小伙伴们来说,还是有点难的。不过在实际应用中内置函数sorted()用的还是蛮多的,这里也单独拿出来讲一下,希望下次再有小伙伴遇到的时候,可以不慌。二、基础用法内置函数sorted()可以用来做排序,基础的用法很简单,看个例子,如下所示。lst=[3,28,18,29,2,5,88

Python 中的 main 函数充当程序的执行点,在 Python 编程中定义 main 函数是启动程序执行的必要条件,不过它仅在程序直接运行时才执行,而在作为模块导入时不会执行。要了解有关 Python main 函数的更多信息,我们将从如下几点逐步学习:什么是 Python 函数Python 中 main 函数的功能是什么一个基本的 Python main() 是怎样的Python 执行模式Let’s get started什么是 Python 函数相信很多小伙伴对函数都不陌生了,函数是可

好嘞,今天我们继续剖析下Python里的类。[[441842]]先前我们定义类的时候,使用到了构造函数,在Python里的构造函数书写比较特殊,他是一个特殊的函数__init__,其实在类里,除了构造函数还有很多其他格式为__XXX__的函数,另外也有一些__xx__的属性。下面我们一一说下:构造函数Python里所有类的构造函数都是__init__,其中根据我们的需求,构造函数又分为有参构造函数和无惨构造函数。如果当前没有定义构造函数,那么系统会自动生成一个无参空的构造函数。例如:在有继承关系

Golang的函数类型断言是一个非常重要的特性,它可以让我们在函数中精细地控制变量的类型,从而更加方便地进行数据处理和转换。本文将介绍Golang函数的类型断言用法,希望能够对大家的学习有所帮助。一、什么是Golang函数的类型断言?Golang函数的类型断言可以理解为函数参数中所声明变量的类型具有多态性,这使得一个函数在不同的参数传递下可以灵活

本篇内容作为以函数为主题的最后一篇,来介绍一下函数返回值以及编写函数的一些基本的最佳实践指导原则。函数输出:返回值函数的返回值是Python领先于竞争对手的东西之一。在大多数其他语言中,函数通常只允许返回一个对象,但是在Python中,你可以返回一个元组——这意味着可以返回任何你想要的东西。这个特性允许程序员编写用其他语言编写的软件要困难得多,或者肯定会更加乏味。我们已经说过,要从函数返回一些东西,我们需要使用return语句,后面跟着我们想要返回的东西。函数体中可以根据需要有多个返回语句。另一


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver Mac版
视觉化网页开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SublimeText3 Linux新版
SublimeText3 Linux最新版