substr

How to remove the first two directories from a file path string?

痞子三分冷 提交于 2020-06-13 09:16:08
问题 I have a string "./product_image/Bollywood/1476813695.jpg". first I remove . from first. now I want to remove all character between first two / . that means I want Bollywood/1476813695.jpg I am trying with this but not work substr(strstr(ltrim('./product_image/Bollywood/1476813695.jpg', '.'),"/product_image/"), 1); It always return product_image/Bollywood/1476813695.jpg 回答1: Easily done with explode() : $orig = './product_image/Bollywood/1476813695.jpg'; $origArray = explode('/', $orig); $new

How to remove the first two directories from a file path string?

纵饮孤独 提交于 2020-06-13 09:15:24
问题 I have a string "./product_image/Bollywood/1476813695.jpg". first I remove . from first. now I want to remove all character between first two / . that means I want Bollywood/1476813695.jpg I am trying with this but not work substr(strstr(ltrim('./product_image/Bollywood/1476813695.jpg', '.'),"/product_image/"), 1); It always return product_image/Bollywood/1476813695.jpg 回答1: Easily done with explode() : $orig = './product_image/Bollywood/1476813695.jpg'; $origArray = explode('/', $orig); $new

Why is substr-lvalue faster than four-arg substr?

旧城冷巷雨未停 提交于 2020-05-15 07:29:07
问题 From this question, we benchmark these two variants, substr( $foo, 0, 0 ) = "Hello "; substr( $foo, 0, 0, "Hello " ); In it we discover that substr -lvalue is faster . To which Ikegami said, How is 4-arg substr slower than lvalue substr (which must create a magical scalar, and requires extra operations)??? – ikegami Truth be told, I also assumed that it would be massively slower and just mentioned it because it was brought up by someone else. Purely for curiosity, Why is substr -lvalue faster

Is it faster to prepend to a string with substr?

浪子不回头ぞ 提交于 2020-05-14 18:42:28
问题 I just found code that prepends with substr( $str, 0, 0, $prepend ) my $foo = " world!" substr( $foo, 0, 0, "Hello " ); Is this any faster than my $foo = " world!" $foo = "Hello $foo"; 回答1: Optrees If we compare the two optrees the top has b <@> substr[t2] vK/4 ->c - <0> ex-pushmark s ->7 7 <0> padsv[$foo:2,3] sM ->8 8 <$> const[IV 0] s ->9 9 <$> const[IV 0] s ->a a <$> const[PV "Hello "] s ->b While the bottom has 8 <+> multiconcat(" world!",-1,7)[$foo:2,3] sK/TARGMY,STRINGIFY ->9 - <0> ex

几个支持中文的PHP字符串截取函数

给你一囗甜甜゛ 提交于 2020-04-07 10:55:24
字符串截取是一个非常常见的编程任务,而往往带中文的字符串截取会经常用到。虽然不难,但是自己写函数实现又耗费时间,这里介绍一个比较好用的字符串截取函数,能够胜任基本的需求了。 <?php function sysSubStr($string,$length,$append = false) { if(strlen($string) <= $length ) { return $string; } else { $i = 0; while ($i < $length) { $stringTMP = substr($string,$i,1); if ( ord($stringTMP) >=224 ) { $stringTMP = substr($string,$i,3); $i = $i + 3; } elseif( ord($stringTMP) >=192 ) { $stringTMP = substr($string,$i,2); $i = $i + 2; } else { $i = $i + 1; } $stringLast[] = $stringTMP; } $stringLast = implode("",$stringLast); if($append) { $stringLast .= "..."; } return $stringLast; } } $string =

SHELL脚本之awk妙用

假装没事ソ 提交于 2020-04-07 08:18:43
对于一个sougou文本文件,解压后大概4G,要求在其基础上切出第一列时间年月日时分秒增加在列中,作为hive的一个索引。先将文件head一下展示格式: [root@Master date]# head -n 5 sogou.full.utf8 20111230000005 57375476989eea12893c0c3811607bcf 奇艺高清 1 1 http://www.qiyi.com/ 20111230000005 66c5bb7774e31d0a22278249b26bc83a 凡人修仙传 3 1 http://www.booksky.org/BookDetail.aspx?BookID=1050804&Level=1 20111230000007 b97920521c78de70ac38e3713f524b50 本本联盟 1 1 http://www.bblianmeng.com/ 20111230000008 6961d0c97fe93701fc9c0d861d096cd9 华南师范大学图书馆 1 1 http://lib.scnu.edu.cn/ 20111230000008 f2f5a21c764aebde1e8afcc2871e086f 在线代理 2 1 http://proxyie.cn/ 最开始不知道awk这个命令

String.prototype.slice()、String.prototype.substr()、String.prototype.substring()

妖精的绣舞 提交于 2020-04-07 05:53:17
String.prototype.slice() slice() 方法提取一个字符串的一部分,并返回一新的字符串。 str.slice(beginSlice[, endSlice]) beginSlice 从该索引(以 0 为基数)处开始提取原字符串中的字符。如果值为负数,会被当做 sourceLength + beginSlice 看待,这里的sourceLength 是字符串的长度 (例如, 如果beginSlice 是 -3 则看作是: sourceLength - 3) endSlice 可选。在该索引(以 0 为基数)处结束提取字符串。如果省略该参数,slice会一直提取到字符串末尾。如果该参数为负数,则被看作是 sourceLength + endSlice,这里的 sourceLength 就是字符串的长度(例如,如果 endSlice 是 -3,则是, sourceLength - 3)。 返回一个从原字符串中提取出来的新字符串 slice 不修改原字符串,只会返回一个包含了原字符串中部分字符的新字符串。 注意:slice() 提取的新字符串包括beginSlice但不包括 endSlice。 var str1 = 'The morning is upon us.'; var str2 = str1.slice(4, -2); console.log(str2);

(kmp)poj 3080 ——Blue Jeans

旧时模样 提交于 2020-04-05 23:04:35
The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how the Earth was populated. As an IBM researcher, you have been tasked with writing a program that will find commonalities amongst given snippets of DNA that can be correlated with individual survey information to identify new genetic markers. A DNA base sequence is noted by listing the nitrogen bases in the order in which they are found in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and

c++句子逆序——substr函数

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-03 21:24:11
#include <iostream> using namespace std; #include <string> // hello world ->world hello int main() { string s, s1, s2; int flag = 0, i = 0; getline(cin, s); for (int j = 0; j < s.size(); j++) { if (s.at(j) == ' ') { s1 = s.substr(flag, j - flag); if (i == 0) { s2 = s1; i++; } else s2 = s1 + " " + s2; flag = j + 1; } if (j == s.size() - 1) { s1 = s.substr(flag, j - flag + 1); s2 = s1 + " " + s2; } } cout << s2; return 0; } 来源: https://www.cnblogs.com/xufeng123/p/12628857.html

字符串函数总结

戏子无情 提交于 2020-03-31 21:45:18
//1.echo print_f exit die 输出 //2.explode 使用一个字符串分割另一个字符串 $a='a,b,c'; echo'<pre>'; var_dump(explode(',',$a)); echo'</pre>'; //3.implode 将一个一维数组的值转化为字符串 $arr=array('a','b','c'); echo implode(',', $arr);//a,b,c //4.trim 去除字符串两边空格 ltrim 去除字符串左边空格 rtrim去除字符串右边空格 $var = ' AB '; echo '#',trim($var),'#'; echo '<br/>'; echo '#',rtrim($var),'#'; echo '<br/>'; echo '#',ltrim($var),'#'; //5.md5,sha1加密函数 echo md5(123456); echo sha1(123456); //6.number_format 以千位分隔符方式格式化一个数字 echo number_format(1234567); //7.str_replace 字符串中的(某个用另一个)替换 str_ireplace 忽略大小写的字符串替换 $c='AaBbCc'; echo str_replace('a', '*',$c);//A