Function: Remove the spaces at the beginning and end of the cell in Excel and retain the spaces in the middle of the string.
Functions used: Mid, find, left, right, trim, substitute, Len
Formula: = Mid (A1, find (left (TRIM (A1), A1), find ("☆", substitute (A1, right (TRIM (A1 )), "☆", Len (A1)-len (substitute (A1, right (TRIM (A1)," ")-find (left (TRIM (A1 )), a1) + 1)
Description: Set the cell to A1. The value is $ AB $ ABA $ ($ indicates space)
1: Find the first non-space characters (RC: Right char) on the Right of A1)
Rc = right (TRIM (A1) ----> rc =
2: Find the number of times RC appears in A1.
N = Len (A1)-len (substitute (A1, RC, "") ----> 3
Substitute (A1, RC, ""): replace RC with null characters
3: Replace the last RC in A1 with "☆" (because" ☆" is not commonly used) (S: string)
S = substitute (A1, "☆", n) ----> get string $ AB ☆$ $
4: Find the "☆" position (that is, the first non-space character on the right) (RF: Right first)
Rf = find ("☆", S) ----> 10
5: Calculate the position of the first non-space character on the left (LF: Left first)
LF = find (left (TRIM (A1), A1) ----> 4
6: RF-LF + 1 characters starting from LF in A1
= Mid (A1, lf, RF-LF + 1)