Google Sheets SUBSTITUTE formula for creating an image path - google-sheets

I'm using the following ARRAYFORMULA to create an image path:
=ARRAYFORMULA(
if(row(A:A)=1,"#Icon",IF(
B:B="",,SUBSTITUTE(
"../../../../../../_Assets/Icons/"& LOWER(B:B&".png"), " ", "_")
)
)
)
What it does
Adding a path before the text and replaces all spaces with an underscore '_'. Here is an example:
Name
#icon
A Tit(l)e
../../../../../../_Assets/Icons/a_tit(l)e.png
Title - Subtitle
../../../../../../_Assets/Icons/title _-_subtitle.png
Title text/string - Subtitle
../../../../../../_Assets/Icons/title_text/string _-_subtitle.png
What I want it to do
If possible, I would like to achieve the following:
Avoiding/removing characters in the list below like the forward slash / with an underscore _ (see the last row in my example above)
It allready replaces all white spaces with an underscore _ which is good. But when it sees a whitespace followed by a - and another whitespace it will output _-_ but then I want only a -
So the current table above would output the following instead:
Name
#icon
A Tit(l)e
../../../../../../_Assets/Icons/a_tit(l)e.png
Title - Subtitle
../../../../../../_Assets/Icons/title-subtitle.png
Title text/string - Subtitle
../../../../../../_Assets/Icons/title_text_string-subtitle.png
List of characters to be avoided/replaced with an underscore _:
# pound
% percent
& ampersand
{ left curly bracket
} right curly bracket
\ back slash
< left angle bracket
> right angle bracket
* asterisk
? question mark
/ forward slash
blank spaces
$ dollar sign
! exclamation point
' single quotes
" double quotes
: colon
# at sign
+ plus sign
` backtick
| pipe
= equal sign
Any help/suggestion would be much appreciated!

Put list of avoided chars into column and use REGEXREPLACE:
=ARRAYFORMULA(if(row(A:A)=1,"#Icon",IF(A:A="",,"../../../../../../_Assets/Icons/"&LOWER(REGEXREPLACE(REGEXREPLACE(A:A," - ","-"),TEXTJOIN("|\",0,D2:D23),"_")) & ".png")))

try:
=ARRAYFORMULA({"#Icon",
IF(B2:B="",,SUBSTITUTE(SUBSTITUTE(
"../../../../../../_Assets/Icons/"&LOWER(B2:B&".png"), " ", "_"), "_-_", "-", 1))})

Related

Leaving behind just numbers in Google Sheets

I have a column in Google Sheets that has phone numbers with the following formats:
(904) 123 4567
+62 123 4567
+12345678
How can I create another column that automatically removes "+", "(", ")" and spaces to produce 9041234567?
Thanks
You can replace all non-digits with nothing.
=ArrayFormula(regexreplace(A2:A4&"", "\D+",))
Change range to suit and/or use an open-ended range
=ArrayFormula(if(len(A2:A), regexreplace(A2:A4&"", "\D+",),))
You can just use REGEXREPLACE to remove the characters you don't want:
=REGEXREPLACE(A1; "[ \(\)\+]"; "")
The expression used [ \(\)\+], removes the character space, right and left parenthesis and the plus sign. Simply add all other characters you want to remove.

How can I remove white spaces between words?

I have text A B c in a spreadhsheet cell.
How can I remove the whitespaces? =Trim is for leading and closing whitespaces.
=REGEXREPLACE(A1, "\s", "") where A1 is your cell with spaces. It uses a regular expression to match any whitespace character, including spaces, tabs, and newlines. If you only want to remove spaces, then use =REGEXREPLACE(A1, " ", "").
Use the Substitute function like this =SUBSTITUTE(B3, " ", ""). Hope it helps.

Replace each pattern in regexp

I'm having some trouble to find the right pattern to get the string I want.
My starting string is :
,,,,C3:,D3,E3,F3,,
I would like to have
C3: [D3,E3,F3]
I would like to replace each starting commas by double space
Replace coma after colon by double space and left square bracket
Replace trailing commas by right square bracket
For now, I tried this :
> a = ",,,,C3:,D3,E3,F3,,"
=> ",,,,C3:,D3,E3,F3,,"
> b = a.gsub(/^,*/, " ").gsub(/(?<=:),/, " [").gsub(/[,]*$/,"" ).gsub(/[ ]*$/, "]")
=> " C3: [D3,E3,F3]"
> b == " C3: [D3,E3,F3]"
=> false
I can't reach to replace each starting comma by a double space to obtain 8 spaces in this case.
Could you help me to find the right regexp and if possible to improve my code, please ?
To replace each starting comma with a double space, you need to use \G operator, i.e. .gsub(/\G,/, ' '). That operator tells the regex engine to match at the start of the string and then after each successful match. So, you only replace each consecutive comma in the beginning of the string with .gsub(/\G,/, ' ').
Then, you can add other replacements:
s.gsub(/\G,/, ' ').sub(/,+\z/, ']').sub(/:,+/, ': [')
See the IDEONE demo
s = ",,,,C3:,D3,E3,F3,,"
puts s.gsub(/\G,/, ' ').sub(/,+\z/, ']').sub(/:,+/, ': [')
Output:
C3: [D3,E3,F3]
To construct the desired string, one needs to know:
the number of leading commas (the size of the string comprised of the leading commas)
the string following the leading commas up to and including the colon
the string between the comma following the colon and two or more commas
It is a simple matter to construct a regex that saves each of these three strings to a capture group:
r = /
(,*) # match leading commas in capture group 1
(.+:) # match up and including colon in capture group 2
, # match comma
(.+) # match any number of any characters in capture group 3
,, # match two commas
/x # extended/free-spacing regex definition mode
",,,,C3:,D3,E3,F3,," =~ r
We can now form the desired string from the contents of the three capture groups:
"#{' '*$1.size}#{$2} [#{$3}]"
#=> " C3: [D3,E3,F3]"

iOS accessibility, how to speak marks within text?

There are some marks just like exclamation mark or question mark, and I found iOS escape them by default. How to speak them out?
Example: 'Tom! First name' or '? My last account'.
You can speak these words to add these marks.... just check
apostrophe ‘
open bracket [
close bracket ]
open parenthesis (
close parenthesis )
open brace {
close brace }
open angle bracket <
close angle bracket >
colon :
comma ,
dash -
ellipsis …
exclamation mark !
hyphen –
period / point / dot / full stop .
question mark ?
quote "
end quote "
begin single quote '
end single quote '
semicolon ;
Typography Result
ampersand &
asterisk *
at sign #
backslash \
forward slash /
caret ^
center dot ·
large center dot •
degree sign °
hashtag / pound sign #
percent sign %
underscore _
vertical bar |

Dispaly special characters ("#") in uitextview content

I have to display "#" in the UITextview content and after to put some information.
I looked on the internet via google but I didn't find an explanation which make
me understand the good approach.
Can you help me with some extra advice ?
Thanks !
You can simply do it like this:
_textView.text=#"#Hi Hello"; result will be #Hi Hello
However if you want to use " in the text you need to append it to backslash \
_textView.text=#"#Hi \"Hello"; result will be #Hi "Hello
You can enter almost all special characters without any problem, but you need to take care for the double quotes:
_textView.text=#"#Hi \"Hello * ! # # $ % ^ & ( ) _ + - [ ] ; ' {} <> ,. / ? : \" ";

Resources