Count specific character in a cell in openoffice calc - openoffice-calc

I have a cell with some text content.
For example: "Red, shirt, size,"
I need to count how many times the comma is used in this cell.
The result should be "3"
Any ideas?

You can use the following formula: LEN(Cell)-LEN(SUBSTITUTE(Cell;"YourCharacter";""))
In your case, the formula would be: LEN(Cell)-LEN(SUBSTITUTE(Cell;",";"").
LEN(Cell) does the following: Counts the number of characters in your cell.
LEN(SUBSTITUTE(Cell;"YourCharacter";"")) counts the number of characters in your cell without the character ",". By subtracting the second formula, you get the number of occurrences of your character.

You can use LEN() function as below
=LEN(cell)-LEN(SUBSTITUTE(cell;",";""))

Related

Extract multiple substrings of numbers of a specific length from string in Google Sheets

I'd need to split or extract only numbers made of 8 digits from a string in Google Sheets.
I've tried with SPLIT or REGEXREPLACE but I can't find a way to get only the numbers of that length, I only get all the numbers in the string!
For example I'm using
=SPLIT(lower(N2),"qwertyuiopasdfghjklzxcvbnm`-=[]\;' ,./!:##$%^&*()")
but I get all the numbers while I only need 8 digits numbers.
This may be a test value:
00150412632BBHBBLD 12458 32354 1312548896 ACT inv 62345471
I only need to extract "62345471" and nothing else!
Could you please help me out?
Many thanks!
Please use the following formula for a single cell.
Drag it down for more cells.
=INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "))=8,
SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "),"")),"where Col1 is not null ",0)))
Functions used:
QUERY
INDEX
TRANSPOSE
IF
LEN
SPLIT
REGEXREPLACE
If you only need to do this for one cell (or you have your heart set on dragging the formula down into individual cells), use the following formula:
=REGEXEXTRACT(" "&N2&" ","\s(\d{8})\s")
However, I suspect you want to process the eight-digit number out of all cells running N2:N. If that is the case, clear whatever will be your results column (including any headers) and place the following in the top cell of that otherwise cleared results column:
=ArrayFormula({"Your Header"; IF(N2:N="",,IFERROR(REGEXEXTRACT(" "&N2:N&" ","\s(\d{8})\s")))})
Replace the header text Your Header with whatever you want your actual header text to be. The formula will show that header text and will return all results for all rows where N2:N is not null. Where no eight-digit number is found, null will be returned.
By prepending and appending a space to the N2:N raw strings before processing, spaces before and after string components can be used to determine where only eight digits exist together (as opposed to eight digits within a longer string of digits).
The only assumption here is that there are, in fact, spaces between string components. I did not assume that the eight-digit number will always be in a certain position (e.g., first, last) within the string.
Try this, take a look at Example sheet
=FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8)
Or this to get them all.
=JOIN(" ,",FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8))
Explanation
SPLIT with the dilimiter set to " " space TRANSPOSE and FILTER TRANSPOSE(SPLIT(B2," ") with the condition1 set to LEN(TRANSPOSE(SPLIT(B2," "))) is = 8
JOIN the outputed column whith " ," to gat all occurrences of number with a length of 8
Note: to get the numbers with the length of N just replace 8 in the FILTER function with a cell refrence.
Using this on a cell worked just fine for me:
(cell_with_data)=REGEXEXTRACT(A1,"[0-9]{8}$")

Remove parts of columns values with regex

I have a dataframe and in 2 columns i have to change values removing all that is not a number or ".". The final result should be only dotted numbers. thank you very much for those of you can help me. I attach how columns areenter image description here
The regex you're after is:
/[0-9.]+/
Explanation:
[0-9.] Looks for one character that is a digit or .
+ repeats last character unlimited times
let regex = /[0-9.]+/;
console.log("1.0.0".match(regex)); //["1.0.0"]
console.log("1.2.4".match(regex)); //["1.2.4"]
console.log("NaN".match(regex)); //[]
console.log("1.1".match(regex)); //["1.1"]
console.log("6.1.61.1".match(regex)); //["6.1.61.1"]
console.log("4.0.3 and up".match(regex)); //["4.0.3"]
This will match any combination of numbers and . of any character length.
For example:

Google Sheets ArrayFormula to get INITIALS of arbitrary length name

Sample sheet.
As the title says, given a column of arbitrary number of words of arbitrary length, Want a single ArrayFormula to get the first letters of all words in the said column.
I have tried two methods, seen in sample sheet.
1) Using SPLIT and ARRAYFORMULA, can get it one cell but cannot extend down column.
2) Using 2 REGEXEXTRACT, can get for first 2 initials and extend down
But is it possible to get for arbitrary number of words for whole column using ArrayFormula.
Is it possible to use REGEXEXTRACT to return the first letters of many words?
This replaces every word with the captured first letter
=ARRAYFORMULA(UPPER(REGEXREPLACE(A1:A6,"(\w)\S*\s?","$1")))

How can I sum the values from a regexextract on multiple rows

I have 3 rows. All of them have a (number)&(letter) format. For example, Say 5&b is present on 3 rows. My question is:
How do I do sum just the numbers? I have tried:
=SUM(REGEXEXTRACT(B3:B, "(.)&."))
I am trying to add the first value of all the rows.
Try:
=ARRAYFORMULA(SUM(--REGEXEXTRACT(B3:B27, "(\d+)&\w+")))
\d+ stands for one or more digits. \w+ will stand for one or more words.
You must use ARRAYFORMULA to extract data from the whole array B3:B27.
-- will convert text to number

How to keep leading zero and add comma in openoffice calc formula?

I have 6 fields in a row in open office, the 1st is a word, the 2nd, 3rd, and 4th are a number with a leading zero, the 5th and 6th are regular numbers. How do I join them all together with a comma between them so that the leading zero stays?
Based on your comment about your numbers having a leading 0 in virtue of a custom number format, you need to incorporate TEXT() functions into your formula to retain (i.e., add) your leading 0s.
=CONCATENATE(A1,",",TEXT(B1,"0#####"),",",TEXT(C1,"0#####"),",",TEXT(D1,"0#####"),",",E1,",",F1)
Just be sure to include as many #'s as the max length of a number in that field.
Please try:
=A1&",0"&B1&",0"&C1&",0"&D1&","&E1&","&F1