substr

substr_count not working with new lines?

[亡魂溺海] 提交于 2019-12-11 07:55:19
问题 This is driving me nuts, it keeps returning 0 substr_count('df d fd f df', '\n'); if I use a letter like "d", it works fine substr_count('df d fd f df', 'd'); Can anyone shed some light on this? Thanks 回答1: You need to use double quotes for control characters: var_dump(substr_count('df d fd f df', "\n")); 回答2: '\n' is not the same as "\n". '\n' is text comprising a slash and the letter "n", whereas "\n" is a newline character. Suggest you read the relevant section of the PHP manual about

Get a substring of a string

谁说胖子不能爱 提交于 2019-12-11 02:22:45
问题 I've been trying to get a substring of a string that contains around 40 lines of text. The string is something like this but with aprox. 30 more lines: Username: example Password: pswd Code: 890382 Key: 9082 type: 1 Website: https://example.com/example Email: example@example.com I need to get the value of, for example, Code which will be 890382 , but I can't seem to do it. Each field like Code or Key is unique in the string. The best (if possible) would be to read the values and store them in

LeetCode刷题记录贴29~32

断了今生、忘了曾经 提交于 2019-12-11 00:38:57
这四题有两题困难的,看起来有点硬核,但是问题不大。这最后四题做完要休息一段时间再做了,最近有点忙,很难受。 29.两数相除 不能用乘法除法,mod,那岂不是只能用减法了,那么我们的任务就是用减法去优化这个过程。 现在喜欢做什么都用递归去写,虽然用递归效率很低,但是写起来帅气,而且可读性要稍微高那么一点。 我服了,下面的代码明明把所有的值都变成负的然后传进递归,但是还是报错我溢出了,莫名其妙卡了好久。。。 int divide ( int dividend , int divisor , int index , int currentAns , int currentIndex ) { if ( dividend > divisor ) return currentIndex ; if ( dividend - ( currentAns + currentAns ) <= 0 ) return divide ( dividend - currentAns - currentAns , divisor , index + index , currentAns + currentAns , currentIndex + index + index ) ; else if ( dividend - currentAns <= 0 ) return divide ( dividend -

substr with characters instead of bytes

ⅰ亾dé卋堺 提交于 2019-12-10 22:44:06
问题 Suppose i have a string s = "101870002PTäPO PVä #Person Tätigkeitsdarstellung 001100001&0111010101101870100092001000010" When I do a substring(30,40) it returns " #Person Tätigkeitsdarstellung" beginning with a space. I guess it's counting bytes instead of characters. Normally the size of the string is 110 and when I do a s.length() or s.size() it returns 113 because of the 3 special characters. I was wondering if there is a way to avoid this empty space at the beginning of the return value.

ORACLE 判断首字母大小写问题

和自甴很熟 提交于 2019-12-10 16:59:51
1.对判断的字段进行拆分 select substr(要区分的字段,0,1) from 表 ; 得到一个 首字母 2.对这个字符进行大小写判断 查出以小写字符为开头的 select substr(要区分的字段,0,1) from 表 where substr(要区分的字段,0,1)=lower((substr(要区分的字段,0,1) )) ; 查出以小写字符为开头的 select substr(要区分的字段,0,1) from 表 where substr(要区分的字段,0,1)=upper((substr(要区分的字段,0,1) )) ; 来源: https://www.cnblogs.com/JIKes/p/12017531.html

Spliting the character into parts

邮差的信 提交于 2019-12-10 16:46:48
问题 I observe the following character: l <- "mod, range1 = seq(-m, n, 0.1), range2 = seq(-2, 2, 0.1), range3 = seq(-2, 2, 0.1)" Using regular expressions in R I desire to split l in the following structure: [1] "mod" "range1 = seq(-m, n, 0.1)" [3] "range2 = seq(-2, 2, 0.1)" "range3 = seq(-2, 2, 0.1)" Unfortunetely, I didn't find a proper way to overcome the problem, yet. Anyone has an idea how is it possible to acquire such an elegeant split? 回答1: I really doubt you can do it with regular

Substr from end of string php?

断了今生、忘了曾经 提交于 2019-12-10 16:39:11
问题 I have this kind of array, i will make it very simple to understand $picture = ( 'artist2-1_thumb.jpg', 'artist2-2.jpg' , 'artist2-3_thumb.jpg', 'artist2-4.jpg', 'artist2-5_thumb.jpg'); Now i want use substr to get new array that only have thumb, to have new array like this $picturethumbs = ( 'artist2-1_thumb.jpg', 'artist2-3_thumb.jpg', 'artist2-5_thumb.jpg'); Can some substr but where to start? 回答1: You could use array_filter() to filter the array, returning only items which match the given

可怕的ORA-600

匆匆过客 提交于 2019-12-10 14:56:52
Dump file /u01/app/oracle/diag/rdbms/ncrac/ncrac12/incident/incdir_107485/ncrac12_j002_706_i107485.trc Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1 System name: Linux Node name: GIO-YW18151 Release: 2.6.18-308.el5 Version: #1 SMP Fri Jan 27 17:17:51 EST 2012 Machine: x86_64 Instance name: ncrac12 Redo thread mounted by this instance: 2 Oracle process number: 284 Unix process pid:

substr doesn't work fine with utf8

跟風遠走 提交于 2019-12-10 13:54:26
问题 I am using a substr method to access the first 20 characters of a string. It works fine in normal situation, but while working on rtl languages (utf8) it gives me wrong results (about 10 characters are shown). I have searched the web but found nth useful to solve this issue. This is my line of code: substr($article['CBody'],0,20); Thanks in advance. 回答1: If you’re working with strings encoded as UTF-8 you may lose characters when you try to get a part of them using the PHP substr function.

How to select sub string in oracle?

旧城冷巷雨未停 提交于 2019-12-10 12:37:35
问题 I have a scenario where my data is something like below: Chapter 18 Unit 10 Sect 16 Case 1 : I want to select Chapter 18 from the above string. Case 2 : I want to select Unit 10 from the above string. Case 3 : I want to select Sect 16 from the above string. 回答1: Using substr: declare l_start number := DBMS_UTILITY.get_cpu_time; begin for i in ( with t as ( select 'Chapter ' || level || ' Unit ' || level || ' Sect ' || level d from dual connect by rownum < 100000 ) select substr(d, 1, instr(d,