find last comma with string SQLITE - sqlite

Is there a way to find last comma with a string and replace it?
There are yellow, blue, green, orange fruits.
to
There are yellow, blue, green and orange fruits.
It would be very simple to find first comma:
substr(text, instr(text, '.'), 1) from table..
But I am looking for a dynamic solution to do it from behind.

If you reverse the string, then using 'instr' would work. You can write a custom function to reverse the string.

Related

Truncate String after ";" in R?

I have some cells with long strings.
I want to truncate the cells within a column, so that only word(s) before a semicolon are maintained. For example, if I have a cell with the string blue house; with green garden I want to only maintain the words before the semicolon, so it would become blue house
Thank you!
If you just want to delete the semi-colon and everything after it then this is a simple pattern that replaces such instances with the empty string: "".
blue <- c('blue house; with green garden')
gsub(";.*$", "", blue)
[1] "blue house"
The previously accepted answer uses a conditional/look-behind and a capture class, both useful concepts, but a bit complex for this simple task.
blue <- c('blue house; with green garden')
gsub('(;*?);.*', '\\1', blue)
[1] "blue house"
appears to work. When using the very nice regex101.com, and you get something to work, remember to add another \ to working examples when you use them in your terminal or RStudio.

How to prevent code from detecting and pulling patterns within words (Example: I want 'one' detected but not 'one' in the word al'one')?

I have this code that is meant to add highlights to some numbers in a text stored in "lines"
stringr::str_replace_all(lines, nums, function(x) {paste0("<<", x, ">>")})
where nums is the following pattern being deteced
nums<-(Zero|One|Two|Three|Four|Five|Six|Seven|Eight|Nine)+\\s?(Hundred|Thousand|Million|Billion|Trillion)?'
The problem I'm having is that the line of code above also leads to numbers embedded in words also being detected. In the following text this happens:
Get <<ten>> eggs. That is what is writ<<ten>>. I am <<one>> and al<<one>>.
when it should be:
Get <<ten>> eggs. That is what is written. I am <<one>> and alone.
I don't want to remove the question mark after the \s because I want to detect both numbers like "One" followed by no space and "One Hundred" which has a space in between.
Does anyone know how to do this?
Surround (Zero|One|Two|Three|Four|Five|Six|Seven|Eight|Nine)+ with \b.
\b matches word boundaries, so this expression will newer match inside a word.

How do I replace linefeeds that come after a specific string with a comma in UNIX

I have some line feeds which come after a certain string, but I want to replace these with commas in unix (but leave all other line feeds alone)
I.e. replace all linefeeds that come after "black and white'
The cat is black and white(linefeed)born in 1985(linefeed)
then I want it to be:
The cat is black and white,born in 1985(linefeed)
This line remains as is:
The cat is black and blue(linefeed)born in 1985(linefeed)

How to Convert a string to Hex?

Is there any way to convert a string to hexa and then to convert it to a .Net color?
I would like to know how to convert a string of color ,say Black, to its Hexa '#000000' ?
i.e. if my input is "Black", i should return "#000000"
My issue is:
i'm setting color and storing its name in an object. So, if it is white, the object keeps "white" ,but for certain shades, it is keeping the name as f12a12 ( an example). I appended "0x" befor such strings and it worked fine with the colortranslator. In case of the normal colors in Color object, i dont want to append this. I can make the string to search through the Colors but i would like to know whether there is any other way to do this?
Color c = Color.Black;
string strColor = System.Drawing.ColorTranslator.ToHtml(c);
//returns 000000
Edit:
In reverse
Color c = System.Drawing.ColorTranslator.FromHtml("#000000");
There is no way to get the HEX from the color name. You need to create a lookup table which holds the name of the color and also the HEX of that color. And only then you can get the HEX of that color.
For your solution I am not sure, but I think to get the correct RGB values you need to have HEX of that color.
ColorTranslator.FromHtml( "#ffffff")

Text box validation using regular expression in asp.net

I have a textbox and have to use the regular expressions in asp.net
My text should not allow the spaces in first and last place.
Output should be:
Valid:
[India Bangalore]
Not valid:
[ India Bangalore ]
i.e : user can enter the spaces in between the words but not in first position and last position.
If you have solution in JavaScript that is also fine.
Trim() should remove any trailing or leading spaces.
Try this please :
^[^\s].*[^\s]$
It simply match input which:
not to start with any white space ^[^\s] followed by any character even white spaces .* and not end with any white space [^\s]$.
Any way calling Trim() method on input string in server-side is much easy .

Resources