How to get particular string from my table? - mysql

My table column contains following sample data:
/Users/abct2/Library/Application Support/iPhone Simulator/4.3/Applications/FD301781-D39F-469E-A604-8164CC9A4493/Library/Caches/List3-ROHAN TEST1/word_306:24:50.jpg
Now, I want to extract any text which comes after /Library/Caches/ (that is List3-ROHAN TEST1/word_306:24:50.jpg). How do I write the select statment for this?
Just FYI, text which is preceding /Library/Caches/ can have any number of slashes.
Please let me know..
Thanks!

If you can assume that "/Library/Caches/" only appears in one position then you can do this:
SUBSTR (text, INSTR(text,'/Library/Caches/')+16)
There are 16 characters in '/Library/Caches/', so the part you want starts 16 characters after the position of '/Library/Caches/' in text.

Related

Replace text next to static text google script

I would like to replace the text in a google doc. At the moment I have place markers as follows
Invoice ##invoiceNumber##
I replace the invoice number with
body.replaceText('##invoiceNumber##',invoiceNumber);
Which is fine but I can only run the script once as obviously ##invoiceNumber## is no longer in the document. I was thinking I could replace the text after Invoice as this will stay the same, appendParagraph looks like it might to the trick but I can't figure it out. I think something like body.appendParagraph("Invoice") would select the area? Not sure how to append to this after that.
You could try something like this I think:
body.replaceText('InvoiceNumber \\w{1,9} ','InvoiceNumber ' + invoicenumber);
I don't know how big your invoice numbers are but that will except from 1 to 9 word characters preceeded by a space and followed by a space. That pattern might have to be modified depending upon your textual needs.
Word Characters [A-Za-z0-9_]
If your invoice numbers are unique enough perhaps you could just replace them.
Reference
Regular Expression Syntax
Note: the regex pattern is passed as a string rather than a regular expression

Excel string to HTML code / inserting text mid string

How do I insert text (a URL link) from another cell (B1) into this cell (C1) containing HTML code like this:
<h4>Features</h4><ul><li>Available in other fabrics</li></ul>
Note:
- The insert text should fill in the tag.
- I tried using concat strings and convert the " into &CHAR(32) but it's not working.
- I have a few thousand rows of this data to work thru. Each URL link is different depending on the productSKU. So this process has to be automated.
- I am not familar with VB.
Thanks for your help.
So it should be something like
=SUBSTITUTE(C1,CHAR(34)&CHAR(34),CHAR(34)&B1&CHAR(34))
assuming the "" only occurs in the href tag.
It's easier than the alternative which would be
=SUBSTITUTE(C1,"""""",""""&B1&"""")
(you have to type a pair of double quotes for each double quote you want)
You might consider defining a name (say q) as =char(34) then it would be
=SUBSTITUTE(C1,q&q,q&B1&q)

right side alt shift in sql

How does one append all lines in a SQL query with text?
In order to add something to the front of my lines of code I can use Alt+Shift down the left side and type something to change
example-1
example-12
example-123
example-1234
example-12345
to
a.example-1
a.example-12
a.example-123
a.example-1234
a.example-12345
but if I want to add something to the right side, it turns out like this
a.example-1*
a.example-1*
a.example-1*3
a.example-1*34
a.example-1*345
when i want it to look like this
a.example-1*
a.example-12*
a.example-123*
a.example-1234*
a.example-12345*
So, how do I do this? Is it possible to append all lines with something with Alt+Shift or is there another method?
*Edit example
To clarify, I need to edit the text in my SQL code, not the text within my tables and such. Ex.:
SELECT TOP 1000
[day]
,[workout_name]
,[reps]
FROM [tom].[dbo].[workout_routine]
but instead of having the commas at the beginning of [day], [workout_name], let's say I need them at the end, like:
SELECT TOP 1000
[day],
[workout_name],
[reps]
FROM [tom].[dbo].[workout_routine]
Because Alt+Shift works and aligns at any column of text, but I need to know if there is a way to be able to add something to the end of lines of differing lengths.
There is a Concat function in mysql.
Select concat(row, ' text after row') from table
If you're looking to modify a script, you can use Regex to replace $ which represents the end of line character. So if you were in Notepad++, you can do a find and replace for $. Make sure you allow Regular expression in the search mode.

MySQL query to return sentence containing a search word from a text column

I need a MySQL query to return a full sentence from a text column that contains a specified search word.
Currently I am able to get the 20 characters before and after the search word using this query:
select id, MID(body,(LOCATE('search_word', body)-20),40) from content where body like "%search_word%" limit 1
, but that's as far as I've got.
I want to get an entire sentence (between two dots) which contains my search word.
Any ideas? Regex? How do I go about doing this?
Why don't you just get the whole field with mysql and filter out the sentence in an actual programming language.
A javascript example would look like this: https://jsfiddle.net/n0wfgjoc/
var text = "Lorem Ipsum is simply dummy text ... versions of Lorem Ipsum.";
var search = "popularised in the";
var pattern = new RegExp('\. ([^.]*' + search + '[^.]*\.)', 'i');
document.getElementsByTagName('body')[0].innerHTML = text.match(pattern)[1];
You should not hve a problem adapting i to your needs - and your language.
It should be much more performant than doing this it in pure SQL.
EDIT:
As #David pointed out, it might be a problem, if there were dots used in the text in other contexts - for abbreviations or dates maybe.
Solving that would be a hard task. My example does not cover that use case.
In PostgreSQL you can do this using regexp_matches, and I believe in MySQL this would be REGEXP_SUBSTR, see also: https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-substr.

How can i replace particular number of letters from particular position?

I need to replace a particular number of characters, for example 3 characters from the 4th position in a string.
How can I do this?
Perhaps you're looking for the STUFF function:
http://msdn.microsoft.com/en-us/library/ms188043.aspx