Find nth occurrence of character in a cell
If you need to find and get the position of nth occurrence of a specific character from a text string as below screenshot shown, there is no direct function for you to solve this task in Excel. This article, I will talk about using a formula which combines the FIND and SUBSTITUTE functions to deal with it.
Find the position of nth occurrence of a specific character in a cell
For example, I have a list of text strings in column A, and now, I want to get the position of the specific characters in column B which appears the nth occurrences, how to solve it?
In Excel, you can combine the FIND and SUBSTITUTE functions for solving this job, the generic syntax is:
- text: The text string or cell value that you want to use.
- N: The nth occurrence of a character that you want to get position.
1. Please enter or copy the below formula into a blank cell where you want to put the result:
Note: In the above formula, A2 is the cell contains the text string that you want to use, B2 is the specific character that you want to find, and C2 is the nth number that you want to get the position of the specific character based on.
2. And then, drag the fill handle down to the cells that you want to apply this formula, and you will get the result as you need:
Explanation of the formula:
SUBSTITUTE(A2,B2,CHAR(160),C2): The SUBSTITUTE function will replace the 3rd occurrence of the character “o” with the char(160) character. It returns the text string as following screenshot shown:
FIND(CHAR(160),SUBSTITUTE(A2,B2,CHAR(160),C2)): This FIND function is used to look for the position of the char(160) character within the new text string returned by the SUBSTITUTE function.
Relative functions used:
- The FIND function is used to find a string within another string, and returns the starting position of the string inside another one.
- The SUBSTITUTE function replaces text or characters within a text string with another text or characters.
- Extract Nth Word From Text String In Excel
- If you have a list of text strings or sentences, now, you want to extract the specific nth word from the list as below screenshot shown. This article, I will introduce some methods for solving this job in Excel.
- Get Or Extract The Last Word From Text String In Excel
- To extract the last word from text string which are separated by the space characters, normally, you can create a formula based on the TRIM, SUBSTITUTE, RIGHT and REPT functions in Excel.
- Extract Last Line Of Text From A Multi-Line Cell
- To extract the last line of text from a text string which is separated by line breaks, normally, there is no direct way for you to solve this. This article, I will introduce a formula to deal with this task in Excel.