text function
text function
Text Functions
Excel has many functions to offer when it comes to manipulating text
strings.
Join Strings
img1
Left
To extract the leftmost characters from a string, use the LEFT function.
img2
Right
To extract the rightmost characters from a string, use the RIGHT function.
img3
Mid
img4
Len
img5
Find
img6
Note: string "am" found at position 3.
Substitute
To replace existing text with new text in a string, use the SUBSTITUTE
function.
img7
2. Separate Strings
This example teaches you how to separate strings in Excel.
img8
The problem we are dealing with is that we need to tell Excel where we
want to separate the string. In case of Smith, Mike the comma is at position
6 while in case of Williams, Janet the comma is at position 9.
Explanation: to find the position of the comma, use the FIND function
(position 6). To get the length of a string, use the LEN function (11
characters). =RIGHT(A2,LEN(A2)-FIND(",",A2)-1) reduces to
=RIGHT(A2,11-6-1). =RIGHT(A2,4) extracts the 4 rightmost characters and
gives the desired result (Mike).
img10
Explanation: to find the position of the comma, use the FIND function
(position 6). =LEFT(A2,FIND(",", A2)-1) reduces to =LEFT(A2,6-1).
=LEFT(A2,5) extracts the 5 leftmost characters and gives the desired result
(Smith).
3. Select the range B2:C2 and drag it down.
img11
3. Number of Instances
This example describes how to count the number of instances of text
(or a number) in a cell.
1. Use the LEN functon to get the length of the string (25 characters,
including spaces).
img12
3. Dividing this number by the length of the word dog (3), gives us the dog
instances (12/3=4).
img14
4. Number of Words
This example describes how to count the number of words in a cell.
1a. The TRIM function returns a string with extra spaces, starting spaces
and ending spaces removed.
img15
1b. To get the length of the string with normal spaces, we combine the LEN
and TRIM function.
img16
2a. The SUBSTITUTE function replaces existing text with new text in a text
string. We use the SUBSTITUTE function to get the string without spaces.
img17
2b. To get the length of the string without spaces, we combine the LEN and
SUBSTITUTE function.
img18
3. Now comes the simple trick. To get the number of words, we subtract the
length of the string without spaces (10) from the length of the string with
normal spaces (12) and add 1.
img19
5. Text to Columns
To separate the contents of one Excel cell into separate columns, you
can use the 'Convert Text to Columns Wizard'. For example, when you
want to separate a list of full names into last and first names.
img20
img22
4. Clear all the check boxes under Delimiters except for the Comma and
Space check box.
5. Click Finish.
img23
Note: This example has commas and spaces as delimiters. You may have
other delimiters in your data. Experiment by checking and unchecking the
different check boxes. You get a live preview of how your data will be
separated.
Result:
img24
6. Lower/Upper Case
This example teaches you how to convert a text string to lower, upper or
proper case in Excel.
img25
img26
3. Use the PROPER function to convert a text string to proper case. That
is, the first letter in each word in uppercase, and all other letters in
lowercase.
img27
The TRIM function returns a string with extra spaces, starting spaces and
ending spaces removed. The CLEAN function removes nonprintable
characters from a string.
1. For example, cell A1 below contains the string " Excel Easy "
img28
img29
Note: the CLEAN function removes this nonprintable character. Text
imported from other applications may contain nonprintable characters.
8. Compare Text
This example shows two ways to compare text in Excel. One is case-
sensitive and one is case-insensitive.
img30
img31
9. Find vs Search
The FIND function and the SEARCH function are very similar to each
other. This example shows the difference.
1. To find the position of a substring in a string, use the FIND function.
FIND is case-sensitive.
img32
img33
Note: string "excel" found at position 11. Even though it's actually the string
"Excel"
img34
img35
Note: A question mark (?) matches exactly one character. An asterisk (*)
matches a series of zero or more characters.
4. One other interesting point to mention about the FIND and the SEARCH
function is that they have a 3rd optional argument. You can use this
argument to indicate the position, counting from the left, at which you want
to start searching.
img36
img37
1a. If you know the text to be replaced, use the SUBSTITUTE function.
img38
1b. The SUBSTITUTE function has a 4th optional argument. You can use
this argument to indicate which occurrence you want to substitute.
img39