FAQ Database Discussion Community


SQLite substr function in WHERE expression

sql,sqlite,substring,substr
Suppose I have 'employee' table with 'lname' column I am interested in fetching all rows, where second character can be either 'e' or 'o' What i am doing wrong, this query doesnt return anything: SELECT * FROM employee WHERE (substr(lname,2,3)='e' OR substr(lname,2,3)='o'); ...

Remove all zero values from string PHP [duplicate]

php,split,substr,strpos
This question already has an answer here: How to strip trailing zeros in PHP 15 answers I have a string like this: 14522354265300000000000 I want to display it without zero values, how I can do this? I do this $pos = strpos($route, '0'); $length = count(str_split($route)); $a = $length...

Simply script using substr to increment IDs

jquery,loops,substr
I have the following code which contains 20 code blocks. They are all the same excepting the ID number for each. I tried looking how to simplify the code pasted below using substr. Can someone please explain if this is posible and offer an example. $( "#ep1box" ).on('mouseover focusin' ,...

How to correctly use SUBSTR, INSTR and or REPLACE in Oracle 11G

string,oracle,replace,oracle11g,substr
What I would like to do is getting the third string. in this example: NL 123456789 TUE that is changed in this example to a number: 2927 123456789 353620 to be (re)placed in the back. So behind the '2927'. I am wondering how to do this? The code that I...

How can I find multiple occurrences of a substring within a string using MySQL Workbench?

mysql,string,recursion,substr,workbench
The query I'm trying to write (using MySQL Workbench) needs to search a text field and return all the occurrences of a "placeholder" substring within the text field. The text I'm searching is actually a document containing placeholders and I would like to see a list of all the placeholders...

how to do multiple sub string replace at same time

php,arrays,str-replace,substr
I want to do multiple sub string replace based on starting and length. Currently I have an array with values (user-id,replace-name,starting,length) my string: "Hi Rameez plz call charlie" sample array : array('123','Rameez Rami',4,6), array('124','Charlie Russet',20,7) And what I want is Rameez to Rameez charlie to Charlie my current code is...

Formatting with awk

bash,shell,printing,awk,substr
Bit of a beginner with awk and was hoping someone could point out where i'm going wrong.. I'm trying to run awk in a script and change the formatting of particular strings matching "objectID" This is the source data: name=SDC1NM519 capacityInKB=1,341,231,104 osType=Windows objectID=LU.R700.53280.24580 displayName=00:60:04 capacityInKB=1,048,576 consumedCapacityInKB=43,008 dpPoolID=10 objectID=LU.R700.53280.24584 displayName=00:60:08 capacityInKB=1,335,885,824...

How to store part of a field value in another column in SQL

sql,substr,self-join
So I'm trying to get a part of a value from a column and insert that part into another column - new column. BOTH columns are in the same table. So what i want should look something like this: id newColumn oldColumn 1 12 123 some text 2 24 246...

Selecting the most recent row by timestamp for multiple entries while joining another table with substring of the current one

sql,oracle,select,join,substr
Ok, the title sounds awfully complicated, but what I actually want to do is not that complex. My tables are: Servicestatustable: ServiceIdentifier ServiceStatus Timestamp System1-Service1 1 sometimestamp System1-Service1 1 sometimestamp System2-Service1 0 sometimestamp System2-Service1 1 sometimestamp System1-Service2 1 sometimestamp System1-Service2 0 sometimestamp System2-Service2 1 sometimestamp System2-Service2 1 sometimestamp System3-Service42 0...

Oracle Date Error - ORA-01841

oracle,substr,to-date,sysdate
I have the following table in Oracle11g. SQL> DESC tmp_test; Name Type Nullable Default Comments -------------------- ------------- -------- ------- -------- SERNO NUMBER(10) CARDNO VARCHAR2(25) Y COL_A VARCHAR2(255) Y DATEA DATE Y DATEB DATE Y TAG VARCHAR2(255) Y FEEDBACK CHAR(1) Y SQL> SQL> SELECT * FROM (SELECT T.COL_A FROM TEMP_TEST T...

Splitting column of a data.frame in R using gsub

regex,r,substr,gsub,strsplit
I have a data.frame called rbp that contains a single column like following: >rbp V1 dd_smadV1_39992_0_1 Protein: AGBT(Dm) Sequence Position 234 290 567 126 Protein: ATF1(Dm) Sequence Position 534 890 105 34 128 301 Protein: Pox(Dm) 201 875 453 ********************* dd_smadv1_9_02 Protein: foxc2(Mm) Sequence Position 145 987 345 907 Protein:...

AWK - using substr integer as part of if condition

bash,if-statement,awk,integer,substr
I'm attempting to use awk one liner to print lines of a file in which the substring is less than a defined variable. Also the line must start with the letter E. The E condition is working, but not the result for the simple if 'less than' I'm looking for....

substr everything after '-' and after detecting ',' in string stop and do it again, how?

php,substr
I have a string looking like this: earth-green, random-stuff, coffee-stuff, another-tag I'm trying to remove everything behind the '-', but when ',' or ' ' is detected, stop and redo the process so the outgoing string becomes earth random coffee another substr($func, 0, strrpos($func, '-')); that removes everything after first...

What is the purpose of strlen($query)-2;

php,substr,strlen
I got this code from google and it fulfills my requirement, but I don't understand the meaning of this line: substr($query,0,strlen($query)-2) Could somebody explain it to me? <?php function insert($tablename, $parameter_order, $values) { $query = "insert into $tablename ("; foreach($parameter_order as $po) { $query .= $po.', '; } $query =...

how to get data between some special characters in ios while string manipulation

ios,string,xcode4,substr
I am trying to get a substring from a string. This is my code: NSString *haystack = @"1:ketan jogal:1 2:ios developer:2"; NSString*[email protected]"1:"; NSString*[email protected]":1"; NSString *prefix = @"2:"; NSString *suffix = @":2"; NSRange needleRange = NSMakeRange(prefix.length, haystack.length - prefix.length - suffix.length); NSRange needlerange1=NSMakeRange(p1.length, haystack.length - prefix.length - s1.length); NSString *needle =...

Split long string into text chunks with jQuery

javascript,jquery,regex,string,substr
I have a long string that needs to be sliced into separated chunks inside an array, with a predefined length limit the chunks. Some rules apply: If the limit cuts a word, then the word is separated for the next chunk. Slices must be trimmed (no spaces at the beginning...

Identify continuously occurring stretch of specific letters in a string using R

r,substr,stringr
I would like to identify if the string column in the data frame below repeats the letters "V" or "G" at least 5 times within the first 20 characters of the string. Sample data: data = data.frame(class = c('a','b','C'), string = c("ASADSASAVVVVGVGGGSDASSSDDDFGDFGHFGHFGGGGGDDFFDDFGDFGTYJ", "AWEERTGVTHRGEFGDFSDFSGGGGGGDAWSDFAASDADAADWERWEQWD", "GRTVVGGVVVGGSWERGERVGEGDDFASDGGVQWEQWEQWERERYRYER")) For example the string in the...

Oracle, substring from right then pad left, odd behavior

oracle,substr
Ok, so i have an ASN_NO, it can be 30 chars. I'm required to take the 10 RIGHT most characters of it. No problem. SUBSTR(ASN_NO,-10, 10) -- this works fine But sometimes the ASN_NO can be less than 10 characters, and in that case i need to pad it with...

Deleting specific characters in a data frame in R

r,substr,gsub
I have data frame like following >sample_df dd_mav2_6541_0_10 dd_mav2_12567_0_2 dd_mav2_43_1_341 dd_mav2_19865_2_13 dd_mav2_1_0_1 I need to remove the all numbers after the foruth "_". I would like have the output like following >sample_df dd_mav2_6541_0 dd_mav2_12567_0 dd_mav2_43_1 dd_mav2_19865_2 dd_mav2_1_0 I tried the following code but it only deletes specific number of characters...

R - Conditional Substr from dataframe

r,data.frame,character,substring,substr
I need to substr from a column based on start and end locations. The start and end locations are derived from a character search. For example, a single column in Dataframe with 3 rows: 'Bond, Mr. :James' 'Woman, Mrs. :Wonder' 'Hood, Mr. :Robin' Expected Answer in Column 2 is: 'Mr.'...

Java equivalent of Php substr()

java,php,function,substring,substr
I am a Java developer but I need a code to be converted from PHP to Java. I need a function which gives equivalent result in Java as of PHP fuction substr (as Java doesn't take negative values whereas php takes). For example: $string = "I am not lonely man";...

Trim a variable's value until it reaches to a certain character

javascript,jquery,variables,substr,texttrimming
so my idea is like this.. var songList = ["1. somesong.mid","13. abcdef.mid","153. acde.mid"]; var newString = myString.substr(4); // i want this to dynamically trim the numbers till it has reached the . // but i wanted the 1. 13. 153. and so on removed. // i have more value's in...

Get a substring of a string

php,string,substring,substr,strpos
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: [email protected] I need to get the value of,...

SQL parse column string for numerical data and store in separate columns

sql,regex,oracle,substr
I am using Oracle SQL and want to parse from a single column of strings generally like suitjacket 899, height195cm weight80kg male blazerjacket 1099, height170cm weight65kg female pants 299, height160cm weight89kgs male coat 1099, height165cms weight60.5kg female Note that sometimes the units are plural with the extra 's' at the...

PHP: Last n characters to a specified character in a string?

php,string,substr
I want to get the last n characters from a string, after the last "-" character. Like: $string = "something-123"; $substring = 123; $string2 = "something-253672-something-21"; $substring2 = 21; These characters can only be numbers. How can I do this with PHP? (sorry for bad english)...

Convert function Remove and Replace on .Net to PHP

php,.net,substring,substr
Let me show my decompiler result with ILSpy for programming Visual C# .NET And at this case, honestly I'm still newbie of programming languange. This is the snip of decompiling coding of Visual C# .NET : private string Oye = "abcdefghijklmnopqrstuvwxyz0123456789"; and these are the the other Class from Visual...

ORA-00939: too many arguments for function in CASE Statement

sql,oracle,syntax,arguments,substr
I'm getting the ORA-00939: too many arguments for function error from my case statement. I have tried splitting it up into multiple CASE statements but still get the same error. CASE WHEN l.fridge_door_modela_id = 'II-SH' THEN 'IW' WHEN l.fridge_door_modela_id = 'IIC-SH' THEN 'IW' WHEN l.fridge_door_modela_id = 'CD' THEN 'RPFX' WHEN...

Change first two characters in string in R

r,substr
In R, I would like to find and replace two characters in string (just first two characters) Here are the data I start with. time <- c("153500", "153800", "161400", "161700", "163000", "161800", "201700", "201800") from <- c("15", "16", "17", "18") to <- c("10","11", "12", "13" ) repl <- data.frame(from, to)...

R6010 abort() has been called

c++,visual-studio-2010,visual-c++,substr
I read about substr from here http://www.cplusplus.com/reference/string/string/substr/ Here is my code : int main() { std::ifstream in ("c:\\users\\admin\\desktop\\aaa.txt"); std::ofstream out ("c:\\users\\admin\\desktop\\bbb.txt"); std::string s ; while ( getline (in,s) ) { std::size_t startpos = s.find("test"); std::string str = s.substr (startpos); out << str << endl; } in.close(); out.close(); } I get...

How do I use the $substr expression in $project operator when using MongoDB 3.0 Java Driver aggregation framework

java,regex,mongodb,substr
I am attempting to integrate a mongoDB process into Java but can't wrap my head around how to integrate the $expressions within the $project operator whilest using the aggregation framework. The perfectly working Mongo query is: db.options.aggregate([{$project:{name:1,lastTradeDate:1,month:{$substr:["$lastTradeDate",4,2]}}},{$out:"Books"}]) Converting this to Java has got me to the following (non-functioning) point: Document...

Take random letters out from a string

javascript,jquery,arrays,substr
I want to remove 3 RANDOM letters from a string. I can use something like substr() or slice() function but it won't let me take the random letters out. Here is the demo of what I have right now. http://jsfiddle.net/euuhyfr4/ Any help would be appreciated!...

Extract and merge strings between different positions

php,arrays,substr
I'm trying to make this works. I want to replace some parts of a sentence between given positions and then show the full sentence with the changes. With the following code, I'm able to make the changes but I don't know how to put together the rest of the sentence....

jQuery / Regex: How to compare string against several substrings

jquery,regex,string,substring,substr
I have a special validation need where I need to check if a string contains ANY out of several substrings like the following list: 12 23 34 45 56 67 78 89 90 01 I am new to jQuery and the only thing I could think of here is the...