substr

Is this a good substr for C?

会有一股神秘感。 提交于 2019-12-06 12:23:06
问题 See also C Tokenizer Here is a quick substr() for C that I wrote (yes, the variable initializations needs to be moved to start of the function etc, but you get the idea) I have seen many "smart" implementations of substr() that are simple one liner calls strncpy()! They are all wrong (strncpy does not guarantee null termination and thus the call might NOT produce a correct substring!) Here is something maybe better? Bring out the bugs! char* substr(const char* text, int nStartingPos, int nRun

Multiply Columns by Substrings in R

你离开我真会死。 提交于 2019-12-06 11:31:45
Suppose I have a dataframe that has multiple components and their properties listed out in multiple columns and I want to run multiple functions against the columns. My approach was to try and base it off the substring in each column header, but I haven't been able to figure out how to do that. Below is an example of the data frame. Basket F_Type_1 F_Qty_1 F_P_1 F_Type_2 F_Qty_2 F_P_2 AAA Apple 10 2.5 Banana 9 2 BBB Peach 5 6 Melon 20 5 I essentially want to cbind two new columns to the end of this dataframe that multiplies Qty and P so you get two new columns at the end like below. F_Total_1

Bash substring expansion on array

会有一股神秘感。 提交于 2019-12-06 09:23:59
I have a set of files with a given suffix. For instance, I have a set of pdf files with suffix .pdf . I would like to obtain the names of the files without the suffix using substring expansion. For a single file I can use: file="test.pdf" echo ${file:0 -4} To do this operation for all files, I now tried: files=( $(ls *.pdf) ) ff=( "${files[@]:0: -4}" ) echo ${ff[@]} I now get an error saying that substring expression < 0 .. ( I would like to avoid using a for loop ) Use parameter expansions to remove the .pdf part like so: shopt -s nullglob files=( *.pdf ) echo "${files[@]%.pdf}" The shopt -s

c语言词法分析器

删除回忆录丶 提交于 2019-12-06 08:35:13
c语言词法分析器 #include<iostream> #include<cstring> #include<cstdio> #include<fstream> #include<map> #include<string> #include<cstdlib> #include<set> #include<fstream> using namespace std; string checkstring(string filewriter,int &i); string checkchar(string filewriter,int &i); string checkdight(string filewriter,int &i); string checkoperator(string filewriter,int &i); bool checkdeadline(char ch); bool checkletterchar(char ch); void error(); string scanner(); string reseve[]= {"","auto","break","case","char","const","continue","default","do","double","else","enum","extern", "float","for","goto","if"

How to delete the last character in the text? [duplicate]

大城市里の小女人 提交于 2019-12-06 08:15:29
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: remove last character from string I want to delete the last character in the text.. For example My string: example text Second : example tex How? 回答1: Use substr $text = 'Example Text'; $text = substr($text, 0, -1) substr takes three arguments, the original text, start and length, it return the substring from the original text starting at start with the given length. If length is negative, that number of

Remove all characters after a specific character in PL/SQL

巧了我就是萌 提交于 2019-12-06 03:10:38
问题 How do I get a substring from this example value: john.abc_1234 I want it to return john.abc .So basically we need to remove all the information after _ . More examples: 1234_abc 回答1: You can use SUBSTR and INSTR : select substr('john.abc_1234', 1, instr('john.abc_1234', '_') -1) from dual Warning: This is only guaranteed to work if your string actually has an underscore in it Update Additionally, if you are running from Oracle 10g on, you could take the Regex path, which would more

c++ can't convert string to wstring

痞子三分冷 提交于 2019-12-05 19:33:35
I would like to convert a string variable to wstring due to some german characters that cause problem when doing a substr over the variable. The start position is falsified when any these special characters is present before it. (For instance: for "ä" size() returns 2 instead of 1) I know that the following conversion works: wstring ws = L"ä"; Since, I am trying to convert a variable, I would like to know if there is an alternative way for it such as wstring wstr = L"%s"+str //this is syntaxically wrong, but wanted sth alike Beside that, I have already tried the following example to convert

20个常用的JavaScript字符串方法

一个人想着一个人 提交于 2019-12-05 12:51:57
摘要: 玩转JS字符串。 原文: JS 前20个常用字符串方法及使用方式 译者:前端小智 Fundebug 经授权转载,版权归原作者所有。 本文主要介绍一些最常用的 JS 字符串函数。 1. charAt(x) charAt(x) 返回字符串中 x 位置的字符,下标从 0 开始。 //charAt(x) var myString = 'jQuery FTW!!!'; console.log(myString.charAt(7)); //output: F 2. charCodeAt(x) `charCodeAt(x)`返回字符串中`x`位置处字符的`unicode`值。 //charAt(position) var message="jquery4u" //alert "113" alert(message.charAt(1) 3. concat(v1,v2..) concat() 方法用于连接两个或多个字符串,此方法不改变现有的字符串,返回拼接后的新的字符串。 //concat(v1, v2,..) var message="Sam" var final=message.concat(" is a"," hopeless romantic.") //alerts "Sam is a hopeless romantic." alert(final) 4. fromCharcode

leetcode每日刷题计划--day59

为君一笑 提交于 2019-12-05 12:31:53
Num 5 最长回文子串 Manacher是专门用于解决这个问题的算法 说明:   1、temp:在所有字符前面插入了#的新字符串,注意最头和最尾巴也插入,这样所有原来字符都在奇数位置   2、maxcenter:已知的最大的回文串中心位置   3、maxend:目前最大回文串覆盖的尾部索引号   4、在判断i的时候,如果他被包含在某个回文串里面,那么他与前面的某个字符附近的东西是对应的,相应的,如果那个字符串在对应部分有回文,那么他的这部分有回文   5、注意限制,如果超出了镜像的部分,是不是不确定,所以下限是min(边界-相同,镜像点的半径)。 几个在leetcode需要注意的地方(字符串堆栈溢出):   1、在插入#产生新的字符串的时候,使用push_back可以避免堆栈溢出(好像是如果给空可能附近有别的干扰,默认分配不够)   2、在后面判断的时候是用temp   3、最后返回的时候用substr返回,s.substr(start,len),第二个是截取长度 class Solution { public: string longestPalindrome(string s) { if(s=="") return ""; string temp="#"; for(int i=0;i<s.length();i++) { //temp[2*i+1]=s[i]; //temp[2

MySql学习笔记

吃可爱长大的小学妹 提交于 2019-12-05 11:07:44
show命令 show status用于显示服务器状态信息 show grants显示授予用户的安全权限。 show errors和show warnings用来显示服务器错误或者警告信息。 limit语句的替换信息 为了区别limit 3,4的含义是从行4开始的3行还是从行3开始的4行,这个容易把人搞糊涂,出于这个原因,MySql 5支持如下的语法: limit 4 offset 3 等价于 limit 3,4 like语句的注意点 在like语句中,是不区分大小写的。 如果要搜索的字符后面含有空格,使用like ‘%keyword’ 是匹配不到 keyword 的。 like ‘%’也不能匹配null mysql中的正则表达式 至3.23.4后,正则表达式不区分大小写,如果要区分大小写,可使用BINARY关键字 如: where pro_name regexp binary 'keyword' 针对特殊字符,如 .、- 需要使用 \\ 为前导, \\- 表示 - , \\. 表示 . 匹配字符类:常用的有如下 定位元字符: [[:<:]] 表示词的开始 [[:>:]] 表示词的结尾 可以在不使用数据表的情况下验证正则表达式。 regexp检查如果没有匹配将返回0,如果匹配将返回1. 如下: SELECT 'hello123' REGEXP '[[:digit:]]' 将返回1