How to replace a string defined by starting and ending index by another string in R?

string <- "this is a funny cat" I want to replace the first 15 characters of string with ‘orange`. The desired output is ‘orange cat’ However, using substr gives me substr(string, 1, 15) <- "orange" > string [1] "oranges a funny cat" which is not the desired output. >Solution : The output of substr should… Read More How to replace a string defined by starting and ending index by another string in R?

how to remove spaces in front of updated values for column in sql?

I have a table which looks like this: Category Name T – 1029 – PHONE sjss T-2629172-LAPTOP ssus T-26124-PC udia T-22 T – 1029 – PHONE I am using this statement to update the ‘Name’ column in my table by getting the entire string after the second dash: update tech_table set name = SUBSTR(Category, INSTR(Category,… Read More how to remove spaces in front of updated values for column in sql?

How to use 'case when' and 'substr' to update a column in oracle sql?

I have a dataset which looks something like this: Category Name T-1029-PHONE sjss T-2629172-LAPTOP ssus T-26124-PC udia T-22 T-1029-PHONE T-1029 I want to update the ‘Name’ column by getting the last part of the ‘Category’ value string after the second ‘-‘ to get the table to look something like this: Category Name T-1029-PHONE PHONE T-2629172-LAPTOP… Read More How to use 'case when' and 'substr' to update a column in oracle sql?

Getting last two digits of Sequence Date in R

I have sequence date: names<-format(seq.Date(as.Date("2012-11-01"),as.Date("2012-12-01"), by = ‘months’),format = "%Y%m") How can I get the last two digit, like the result for last two digits of names[1] is 11? >Solution : Using the stringr package you can just put stringr::str_sub(string = names, start = -2, end = -1)

C++ substring not giving me the correct result

I have the following code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() { fstream file; string s; //file contains the following //id="123456789" //Note: There is no spaces at the end file.open("test.txt", ios::in); getline(file, s); s = s.substr(s.find("\"")+1, s.length()-1); cout << s << endl; return 0; } The results print: 123456789" Why… Read More C++ substring not giving me the correct result

SQL Join Using REGEXP_SUBSTR and Wildcard

I’m trying to join two tables in Snowflake using REGEX_SUBSTR and a wildcard but having no luck. Here is what I have: SELECT P.NAME, ACL.CONTENT_NAME, REGEXP_SUBSTR(CONTENT_NAME, ‘/([^/]+(\\.pdf))$’, 1, 1, ‘e’, 1) AS PDFS FROM ACTIVITY_DOWNLOAD AD JOIN PROGRAM P ON P.NAME LIKE ‘%’ || REGEXP_SUBSTR(CONTENT_NAME, ‘/([^/]+(\\.pdf))$’, 1, 1, ‘e’, 1) || ‘%’ Running the query… Read More SQL Join Using REGEXP_SUBSTR and Wildcard

Extracting a string with regular expressions that contains a certain word anywhere in the string

I am having a hard time understanding regex syntax for this specific issue I am facing. I am using Python. Here is a sample output (with random values) of sensors I am using that is in a txt file: Sensors starting {‘device_id’: ‘M123’} {‘x_acc’: 0.00, ‘y_acc’ : 0.01, ‘z_acc’ : 1.02} But from another device… Read More Extracting a string with regular expressions that contains a certain word anywhere in the string

Dataframe conditional replacement with intigers

I have a dataframe column like this: df[‘col_name’].unique() >>>array([-1, ‘Not Passed, On the boundary’, 1, ‘Passed, On the boundary’, ‘Passed, Unclear result’, ‘Passes, Unclear result, On the boudnary’, ‘Rejected, Unclear result’], dtype=object) In this column, if an element contains the word ‘Passed’ as a field or as a substring, then replace the entire field with… Read More Dataframe conditional replacement with intigers