Excel replace symbol in string

Содержание

  1. REPLACE, REPLACEB functions
  2. Description
  3. Syntax
  4. Example
  5. How to Remove a Specific Character from a String in Excel
  6. Removing a Specific Character with the Find and Replace Feature
  7. Removing a Specific Character with the SUBSTITUTE Function
  8. Removing only a Particular Instance of a Specific Character in a String
  9. Removing any Special Character with the CLEAN Function
  10. Removing Leading or Trailing Space Characters with the TRIM Function
  11. Removing a Specific Invisible Character from a String using SUBSTITUTE, CHAR and CODE Functions

REPLACE, REPLACEB functions

This article describes the formula syntax and usage of the REPLACE and REPLACEB function in Microsoft Excel.

Description

REPLACE replaces part of a text string, based on the number of characters you specify, with a different text string.

REPLACEB replaces part of a text string, based on the number of bytes you specify, with a different text string.

These functions may not be available in all languages.

REPLACE is intended for use with languages that use the single-byte character set (SBCS), whereas REPLACEB is intended for use with languages that use the double-byte character set (DBCS). The default language setting on your computer affects the return value in the following way:

REPLACE always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is.

REPLACEB counts each double-byte character as 2 when you have enabled the editing of a language that supports DBCS and then set it as the default language. Otherwise, REPLACEB counts each character as 1.

The languages that support DBCS include Japanese, Chinese (Simplified), Chinese (Traditional), and Korean.

Syntax

REPLACE(old_text, start_num, num_chars, new_text)

REPLACEB(old_text, start_num, num_bytes, new_text)

The REPLACE and REPLACEB function syntax has the following arguments:

Old_text Required. Text in which you want to replace some characters.

Start_num Required. The position of the character in old_text that you want to replace with new_text.

Num_chars Required. The number of characters in old_text that you want REPLACE to replace with new_text.

Num_bytes Required. The number of bytes in old_text that you want REPLACEB to replace with new_text.

New_text Required. The text that will replace characters in old_text.

Example

Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.

Источник

How to Remove a Specific Character from a String in Excel

A big part of processing data involves the cleaning of the data.

Most data you bring in to Excel often comes from various sources. Many times they are converted from a different format. As such, it is not uncommon to find unwanted characters inside text string data.

What’s more annoying is that sometimes these unwanted characters are invisible. So they fail to give expected results when operations are performed on them. Another common problem is the presence of inconsistent blank spaces.

In this tutorial, we will address all the above issues using Excel functions, formulas, and features. We will see how to use various Excel functionalities to remove specific characters from strings in your cells.

Table of Contents

Removing a Specific Character with the Find and Replace Feature

Excel’s Find and Replace dialog box is a great way to find items on your worksheet and get things done quickly.

All you need to do is enter your search string to specify what you want to replace and then specify what you want to replace it with.

Suppose you have the below dataset and you want to remove all the ‘@’ characters from the text string in each cell.

Below are the steps to remove a specific character using Find and Replace:

  1. Select the range of cells you want to work with.
  2. Click on Find & Select from the Home tab (under the ‘Editing’ group).
  3. This will display a dropdown menu. Select ‘Replace’.
  4. This will open the Find and Replace dialog box. Type ‘@’ in the text box next to ‘Find what’.
  5. Leave the text box next to ‘Replace with’ blank. This is because you want to remove any instance of the ‘@’ symbol in each cell.
  6. Click on the ‘Replace All’ button.

This will remove all instances of the ‘@’ symbol from all the cells.

Removing a Specific Character with the SUBSTITUTE Function

The SUBSTITUTE function can be used to remove a specific character from a string or replace it with something else. The general syntax for this function is:

  • original_string is the text or reference to the cell that you want to work on.
  • old_character is the character that you want to replace.
  • new_character is the character that you want to replace old_character with.
  • instance_number is optional. It is the instance of the old_character that you want to replace.

It is possible to customize the above formula to the make it suitable to remove a specific character from a string, as follows:

This formula will replace the old_character with a blank (“”), which means the character will basically get deleted.

Let us assume you have the same set of string values with the ‘@’ symbol in random places, and you want to remove all of them:

For this, you can use the SUBSTITUTE function with the following steps:

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell B2.
  2. Type the formula:
  3. Press the return key.
  4. This will give you the text obtained after removing all instances of the ‘@’ symbol in cell A2.
  5. Double click the fill handle (located at the bottom-left corner) of cell B2. This will copy the formula to all the other cells of column B. You can also choose to drag down the fill handle to achieve the same effect. Here are both the original and converted columns side by side:
  6. If you want to retain only the converted versions of the text, then select these cells (B2:B5), copy them, and paste them in the same place as values.
  7. You can then delete column A if you need to.

Removing only a Particular Instance of a Specific Character in a String

Now, what if you wanted to remove just the first ‘@’ symbol from each cell, instead of all instances of them?

This is where the last optional parameter of the SUBSTITUTE function comes in handy.

Using this, you can specify which instance of the symbol you want to remove. So, to remove the first instance of a symbol, your function should be:

Similarly, if you want to remove the second instance of the character, the function will be:

Let’s see the steps to remove only the first instance of the ‘@’ symbol from the above dataset:

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell B2.
  2. Type the formula:
  3. Press the return key.
  4. This will give you the text obtained after removing only the first ‘@’ symbol in cell A2.
  5. Double click the fill handle (located at the bottom-left corner) of cell B2. This will copy the formula to all the other cells of column B. You can also choose to drag down the fill handle to achieve the same effect. Here are both the original and converted columns side by side:
  6. If you want to retain only the converted versions of the text, then select these cells (B2:B5), copy them, and paste them in the same place as values.
  7. You can then delete column A if you need to.

Removing any Special Character with the CLEAN Function

The Excel CLEAN function removes line breaks and non-printable characters from a string. The general syntax for this function is:

Here, original_string is the text or reference to the text cell that you want to clean.

The result is the text that has all non-printable characters removed.

Let’s take a look at the following set of strings.

Since the list was brought in from another application, it ended up having a lot of unnecessary characters, like new-line characters, spaces, etc.

Let’s see how to use the CLEAN function to clean this data:

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell B2.
  2. Type the formula:
  3. Press the return key.
  4. This will give you the text obtained after removing all line breaks from the string in cell A2.
  5. Double click the fill handle (located at the bottom-left corner) of cell B2. This will copy the formula to all the other cells of column B.

Notice that the new line characters got removed, but the results still don’t look right. This is because when the data was brought in, it also contained some space characters, besides the new lines.

The CLEAN function removes only the first 32 (non-printable) characters in the 7-bit ASCII code (i.e. values 0 to 31). However, there are other non-printable characters in Unicode that CLEAN cannot remove.

Since the space character has a value of 32, the CLEAN function does not remove spaces. So it is best to apply the TRIM function after applying the CLEAN function to remove the spaces.

Removing Leading or Trailing Space Characters with the TRIM Function

A lot of data cleaning merely consists of removing leading or trailing space characters from strings. Excel’s TRIM function makes this easy to do in just one go.

The TRIM function removes the space character (“ “) from the text. If the spaces are leading or trailing spaces, it removes all of them. If there are extra spaces between words, then it removes the extras and leaves just a single space.

The general syntax for this function is:

Here, original_string is the text or reference to the text cell that you want to process.

Let us use the TRIM function to remove the space characters that were left over after applying the CLEAN function:

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell C2.
  2. Type the formula:
  3. Press the return key.
  4. This will give you the text obtained after removing all unnecessary spaces from the string in cell B2.
  5. Double click the fill handle (located at the bottom-left corner) of cell C2. This will copy the formula to all the other cells of column C.
  6. If you want to retain only the converted versions of the text, then select these cells (C2:C5), copy them, and paste them in the same place as values.
  7. You can then delete columns A and B if you need to.

Removing a Specific Invisible Character from a String using SUBSTITUTE, CHAR and CODE Functions

In some cases, both CLEAN and TRIM functions fail to remove some particularly annoying characters from the string.

This may be because these characters are neither spaces nor one of the 32 characters that the CLEAN function can remove.

You can find the code of a character by using the CODE function. For example, in the sample text below, there is an invisible character at the start of the string.

Since it couldn’t be removed with a TRIM or CLEAN, it is quite evident that it’s not a regular space.

Here’s what we can do to remove all instances of the invisible character:

  1. To find out what this character is, we can use the CODE function. Type this function into the cell B2: =CODE(LEFT(A2)). Since the character is in the first position in the text, we can easily find out its code using the LEFT function. In this case, we get the result as “160”. That means the invisible character’s code is 160.
  2. Let us use this value in the SUBSTITUTE function. Type this function into the cell C2: =SUBSTITUTE(A2,CHAR(B2),””). Here we used the CHAR function to convert the character code back to its character equivalent.
  3. When you press the return key now, you will find all instances of that invisible character removed from the string.

In this tutorial, we saw how you can use various Excel functions, formulas, and features to remove specific characters from a string.

If you know what the character you want to remove is, you can use either the Find and Replace feature or the SUBSTITUTE function.

To remove blank spaces and special characters (that often accompany data brought in from other applications) you can use the CLEAN and TRIM functions respectively.

If there are other invisible characters in the string and you don’t know what the characters are, you can use a formula that combines the CODE, CHAR, and SUBSTITUTE functions together.

We tried to put together all possible situations where you would need to remove a specific character from text in Excel.

Hope you found the tutorial useful!

Other Excel tutorials you may like:

Источник

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 Excel Starter 2010 More…Less

This article describes the formula syntax and usage of the REPLACE and REPLACEB
 function in Microsoft Excel.

Description

REPLACE replaces part of a text string, based on the number of characters you specify, with a different text string.

REPLACEB replaces part of a text string, based on the number of bytes you specify, with a different text string.

Important: 

  • These functions may not be available in all languages.

  • REPLACE is intended for use with languages that use the single-byte character set (SBCS), whereas REPLACEB is intended for use with languages that use the double-byte character set (DBCS). The default language setting on your computer affects the return value in the following way:

  • REPLACE always counts each character, whether single-byte or double-byte, as 1, no matter what the default language setting is.

  • REPLACEB counts each double-byte character as 2 when you have enabled the editing of a language that supports DBCS and then set it as the default language. Otherwise, REPLACEB counts each character as 1.

The languages that support DBCS include Japanese, Chinese (Simplified), Chinese (Traditional), and Korean.

Syntax

REPLACE(old_text, start_num, num_chars, new_text)

REPLACEB(old_text, start_num, num_bytes, new_text)

The REPLACE and REPLACEB function syntax has the following arguments:

  • Old_text    Required. Text in which you want to replace some characters.

  • Start_num    Required. The position of the character in old_text that you want to replace with new_text.

  • Num_chars    Required. The number of characters in old_text that you want REPLACE to replace with new_text.

  • Num_bytes    Required. The number of bytes in old_text that you want REPLACEB to replace with new_text.

  • New_text    Required. The text that will replace characters in old_text.

Example

Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.

Data

abcdefghijk

2009

123456

Formula

Description (Result)

Result

=REPLACE(A2,6,5,»*»)

Replaces five characters in abcdefghijk with a single * character, starting with the sixth character (f).

abcde*k

=REPLACE(A3,3,2,»10″)

Replaces the last two digits (09) of 2009 with 10.

2010

=REPLACE(A4,1,3,»@»)

Replaces the first three characters of 123456 with a single @ character.

@456

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

A big part of processing data involves the cleaning of the data.

Most data you bring in to Excel often comes from various sources. Many times they are converted from a different format. As such, it is not uncommon to find unwanted characters inside text string data.

What’s more annoying is that sometimes these unwanted characters are invisible. So they fail to give expected results when operations are performed on them. Another common problem is the presence of inconsistent blank spaces.

In this tutorial, we will address all the above issues using Excel functions, formulas, and features. We will see how to use various Excel functionalities to remove specific characters from strings in your cells.

Removing a Specific Character with the Find and Replace Feature

Excel’s Find and Replace dialog box is a great way to find items on your worksheet and get things done quickly.

All you need to do is enter your search string to specify what you want to replace and then specify what you want to replace it with.

Suppose you have the below dataset and you want to remove all the ‘@’ characters from the text string in each cell.

Data from which a character needs to be removed

Below are the steps to remove a specific character using Find and Replace:

  1. Select the range of cells you want to work with.
  2. Click on Find & Select from the Home tab (under the ‘Editing’ group).Click on Replace
  3. This will display a dropdown menu. Select ‘Replace’.
  4. This will open the Find and Replace dialog box. Type ‘@’ in the text box next to ‘Find what’.
  5. Leave the text box next to ‘Replace with’ blank. This is because you want to remove any instance of the ‘@’ symbol in each cell.
  6. Click on the ‘Replace All’ button.Click on the replace all button

This will remove all instances of the ‘@’ symbol from all the cells.

Data after character has been removed

Removing a Specific Character with the SUBSTITUTE Function

The SUBSTITUTE function can be used to remove a specific character from a string or replace it with something else. The general syntax for this function is:

=SUBSTITUTE (original_string, old_character, new_character, instance_number)

Here,

  • original_string is the text or reference to the cell that you want to work on.
  • old_character is the character that you want to replace.
  • new_character is the character that you want to replace old_character with.
  • instance_number is optional. It is the instance of the old_character that you want to replace.

It is possible to customize the above formula to the make it suitable to remove a specific character from a string, as follows:

=SUBSTITUTE (original_string, old_character, “”)

This formula will replace the old_character with a blank (“”), which means the character will basically get deleted.

Let us assume you have the same set of string values with the ‘@’ symbol in random places, and you want to remove all of them:

Data from which a character needs to be removed

For this, you can use the SUBSTITUTE function with the following steps:

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell B2.
  2. Type the formula:
    =SUBSTITUTE(A2,"@","")
  3. Press the return key.
  4. This will give you the text obtained after removing all instances of the ‘@’ symbol in cell A2.remove all @ using substitute
  5. Double click the fill handle (located at the bottom-left corner) of cell B2. This will copy the formula to all the other cells of column B. You can also choose to drag down the fill handle to achieve the same effect. Here are both the original and converted columns side by side:Copy substitute formula for entire column
  6. If you want to retain only the converted versions of the text, then select these cells (B2:B5), copy them, and paste them in the same place as values.
  7. You can then delete column A if you need to.
Also Read: How to Remove the Last Digit in Excel?

Removing only a Particular Instance of a Specific Character in a String

Now, what if you wanted to remove just the first ‘@’ symbol from each cell, instead of all instances of them?

This is where the last optional parameter of the SUBSTITUTE function comes in handy.

Using this, you can specify which instance of the symbol you want to remove. So, to remove the first instance of a symbol, your function should be:

SUBSTITUTE (original_string, old_character, “”,1)

Similarly, if you want to remove the second instance of the character, the function will be:

SUBSTITUTE (original_string, old_character, “”,2)

Let’s see the steps to remove only the first instance of the ‘@’ symbol from the above dataset:

Data from which a character needs to be removed

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell B2.
  2. Type the formula:
    =SUBSTITUTE(A2,"@","",1)
  3. Press the return key.
  4. This will give you the text obtained after removing only the first ‘@’ symbol in cell A2.substitute function to remove a character from a text string
  5. Double click the fill handle (located at the bottom-left corner) of cell B2. This will copy the formula to all the other cells of column B. You can also choose to drag down the fill handle to achieve the same effect. Here are both the original and converted columns side by side:Only the first instance of the character is removed
  6. If you want to retain only the converted versions of the text, then select these cells (B2:B5), copy them, and paste them in the same place as values.
  7. You can then delete column A if you need to.
Also read: How to Remove First Character in Excel?

Removing any Special Character with the CLEAN Function

The Excel CLEAN function removes line breaks and non-printable characters from a string. The general syntax for this function is:

=CLEAN (original_string)

Here, original_string is the text or reference to the text cell that you want to clean.

The result is the text that has all non-printable characters removed.

Let’s take a look at the following set of strings.

Dataset with special strings

Since the list was brought in from another application, it ended up having a lot of unnecessary characters, like new-line characters, spaces, etc.

Let’s see how to use the CLEAN function to clean this data:

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell B2.
  2. Type the formula:
    =CLEAN(A2).
  3. Press the return key.
  4. This will give you the text obtained after removing all line breaks from the string in cell A2.
  5. Double click the fill handle (located at the bottom-left corner) of cell B2. This will copy the formula to all the other cells of column B.Result after using the CLEAN function

Notice that the new line characters got removed, but the results still don’t look right. This is because when the data was brought in, it also contained some space characters, besides the new lines.

The CLEAN function removes only the first 32 (non-printable) characters in the 7-bit ASCII code (i.e. values 0 to 31). However, there are other non-printable characters in Unicode that CLEAN cannot remove.

Since the space character has a value of 32, the CLEAN function does not remove spaces. So it is best to apply the TRIM function after applying the CLEAN function to remove the spaces.

Removing Leading or Trailing Space Characters with the TRIM Function

A lot of data cleaning merely consists of removing leading or trailing space characters from strings. Excel’s TRIM function makes this easy to do in just one go.

The TRIM function removes the space character (“ “) from the text. If the spaces are leading or trailing spaces, it removes all of them. If there are extra spaces between words, then it removes the extras and leaves just a single space.

The general syntax for this function is:

=TRIM (original_string)

Here, original_string is the text or reference to the text cell that you want to process.

Let us use the TRIM function to remove the space characters that were left over after applying the CLEAN function:

Result after using the CLEAN function

  1. Select the first cell of the column where you want the results to appear. In our example, it will be cell C2.
  2. Type the formula:
    =TRIM(B2).
  3. Press the return key.
  4. This will give you the text obtained after removing all unnecessary spaces from the string in cell B2.
  5. Double click the fill handle (located at the bottom-left corner) of cell C2. This will copy the formula to all the other cells of column C.Result after using trim function
  6. If you want to retain only the converted versions of the text, then select these cells (C2:C5), copy them, and paste them in the same place as values.
  7. You can then delete columns A and B if you need to.Delete the column

Removing a Specific Invisible Character from a String using SUBSTITUTE, CHAR and CODE Functions

In some cases, both CLEAN and TRIM functions fail to remove some particularly annoying characters from the string.

This may be because these characters are neither spaces nor one of the 32 characters that the CLEAN function can remove.

You can find the code of a character by using the CODE function. For example, in the sample text below, there is an invisible character at the start of the string.

Since it couldn’t be removed with a TRIM or CLEAN, it is quite evident that it’s not a regular space.

Dataset

Here’s what we can do to remove all instances of the invisible character:

  1. To find out what this character is, we can use the CODE function. Type this function into the cell B2: =CODE(LEFT(A2)). Since the character is in the first position in the text, we can easily find out its code using the LEFT function. In this case, we get the result as “160”. That means the invisible character’s code is 160.using the code function
  2. Let us use this value in the SUBSTITUTE function. Type this function into the cell C2: =SUBSTITUTE(A2,CHAR(B2),””). Here we used the CHAR function to convert the character code back to its character equivalent.
  3. When you press the return key now, you will find all instances of that invisible character removed from the string.using substitute fucntion to remove the character

In this tutorial, we saw how you can use various Excel functions, formulas, and features to remove specific characters from a string.

If you know what the character you want to remove is, you can use either the Find and Replace feature or the SUBSTITUTE function.

To remove blank spaces and special characters (that often accompany data brought in from other applications) you can use the CLEAN and TRIM functions respectively.

If there are other invisible characters in the string and you don’t know what the characters are, you can use a formula that combines the CODE, CHAR, and SUBSTITUTE functions together.

We tried to put together all possible situations where you would need to remove a specific character from text in Excel.

Hope you found the tutorial useful!

Other Excel tutorials you may like:

  • How to Remove Text after a Specific Character in Excel
  • How to Remove Question Marks from Text in Excel?
  • How to Remove Commas in Excel (from Numbers or Text String)
  • How to Remove Dollar Sign in Excel
  • How to Remove Apostrophe in Excel
  • How to Add Text to the Beginning or End of all Cells in Excel
  • How to Reverse a Text String in Excel (Using Formula & VBA)
  • How to Change All Caps to Lowercase Except the First Letter in Excel?
  • How to Extract Text After Space Character in Excel?
  • Extract Last Name in Excel
  • How to Separate Names in Excel
  • How to Remove Space before Text in Excel

Part of what you want to do can be accomplished with the «SUBSTITUTE» function.

This will replace specific characters in a text string with the characters you specify, in this case spaces with the + symbol.

Then to change case use the «LOWER» function.

If you nest «SUBSTITUTE» within «LOWER» you should get the change you are looking for.

The text below is taken from Excel Help.


SUBSTITUTE

Substitutes new_text for old_text in a text string. Use SUBSTITUTE when you want to replace specific text in a text string; use REPLACE when you want to replace any text that occurs in a specific location in a text string.

Syntax

SUBSTITUTE(text,old_text,new_text,instance_num)

Text is the text or the reference to a cell containing text for which you want to substitute characters.

Old_text is the text you want to replace.

New_text is the text you want to replace old_text with.

Instance_num specifies which occurrence of old_text you want to replace with new_text. If you specify instance_num, only that instance of old_text is replaced. Otherwise, every occurrence of old_text in text is changed to new_text.


LOWER

Converts all uppercase letters in a text string to lowercase.

Syntax

LOWER(text)

Text is the text you want to convert to lowercase. LOWER does not change characters in text that are not letters.

If you have A:B:C:D in cell A1, then this works:

=CONCATENATE(MID(A1, 1, SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + SEARCH(":", A1)), "Z", MID(MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) - SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1), SEARCH(":", MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) - SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1)), LEN(MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) - SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1))))

I know it’s incredibly convoluted but it works.

EDIT: And to be clear, you’d replace «Z» with the data you want to add in.

Понравилась статья? Поделить с друзьями:
  • Excel replace if found
  • Excel replace function all
  • Excel replace comma with dot
  • Excel replace all cells with text
  • Excel repack by kpojiuk