Excel functions for text cleaning
1.find function
Description: The function find is used to locate the first text string in the second text string and return the starting position of the first text string
For example, there are two first text strings in the second text string. According to the starting position, the position of the first first text string that matches with it is returned.
语法:=find(find_text,within_text,[start_num])
Remarks: find_text is required, the text to be found
within_text is required, is the text that contains the text to be found
start_num optional, specify the character to start the search
The first character in within_text is the character number 1. If start_num, the default value is 1.
find is case sensitive and does not allow wildcards.
Example: A1 = 10k-20k
(1) =find("k",A1,1) returns 3
(2) =find("k",A1,2) returns 3
(3) =find("k",A1,4) returns 7
Note: The returned numbers are all counting from 1, and you need to judge the position of the first text you want to find based on start_num
2.left function
Description: left returns the specified number of characters starting from the first character of the text string
Syntax: left(text,[num_chars])
Remarks: text is required, a text string containing the string to be extracted
num_chars is optional, specifies the number of characters to be extracted by left
If num_chars is greater than the text length, left returns all text
If num_chars is omitted, the default value is 1.
Example: A2 = 10k-20k
(1) Take out 10, the first step needs to determine the position of "k" in 10k according to the find function, and the second step takes the value according to the left function
=find("k",A2,1) returns 3
=left(A2,3-1) returns 10
(2) Take out 20
=find("-",A2,1) returns 4
=right(A2,4-1) returns 20k
Use the <Replace> button to replace k with a space
3.right function
Similar to the use of the left function
4.mid function
Description: Returns a specific number of characters from the specified position in the text string, the number is specified by the user
Syntax: =mid(text,start_num,num_chars)
Remarks: text is required, the text string containing the characters to be extracted
start_num is required. The position of the first character to be extracted in the text. The start_num of the first character in the text is 1, and so on
num_chars is required. Specify the number of characters you want mid to return from the text
Example: A2 = 10k-20k
(1)=mid(A2,1,2) returns 10
(2) Extract 20
The first step is to find the position of "-"=find("-",A2,1) The return result is 4
The second step is to find the position of the second "k" = find("k",A2,4) returns 7
=mid(A2,4+1,2) returns 20
5.concatenate function
&"|concatenate
(1) When the amount of connection is small, you can choose the "&" connector
Example: =8&"k" returns 8k
="big"&"_"&"small"返回 big_small
(2) Concatenate function
Syntax: concatenate(text1,text2,...)
=concatenate(8,"k") returns 8k
=concatenate("big","_","small") 返回 big_small
6.replace function
Description: According to the specified number of characters, replace replaces part of the text string with a different text string, which is to find and replace according to the text position
Syntax: replace(old_text,start_num,num_chars,new_text)
old_text: must be the text that replaces some of its characters
start_num: The starting position of the character to be replaced with new_text in the required old_text
num_chars: required number of characters in old_text that you want to replace using new_text to replace
new_text: The text that must replace the characters in old_text
Example: A2 = 10K-20K
=replace(A2,4,2,"*") returns 10K*0K
7. Substitute function
Description: Replace old_text with new_text in the text string. If you need to replace the specified text in a text string, please use the function substitute; if you need to replace any text at a specific position in a text string, please use the replcae function.
Syntax: =substitute(text,old_text,new_text,[instance_num])
Remarks: text is required, the text in which characters need to be replaced, or a reference to the cell containing text (the characters need to be replaced)
old_text required, the text to be replaced
new_text is required, used to replace old_text text
instance_num is optional and specifies the event to replace old_text with new_text. If instance_num is specified, only old_text that meets the requirements will be replaced. Otherwise, all old_text that always appears in the text will be changed to new_text.
Example: A2 = 10k-20k
(1)=SUBSTITUTE(M2,"k","千") returns a result of 10 thousand-20 thousand
(2)=SUBSTITUTE(M2,"k","千",1) returns 10 thousand-20k
(3) =SUBSTITUTE(M2,"k","千",2) returns 10k-20 thousand
8.trim function
Note: except for a single space between words, remove all spaces in the text
Syntax: trim(text)
Remarks: text is required, the text from which spaces should be removed
事例:=trim(" a big house ") 返回a big house
Remove leading and trailing spaces from the text of the formula
9.len function
Description: Returns the number of characters in the text string
Syntax: len(text)
Remarks: text is required, to find the length of the text. Spaces will be counted as characters
Example: =len("a big house") returns 12. The spaces in the middle and the end are counted as characters