Aman
Aman

Reputation: 671

removing whitespaces not working MySQL. Used TRIM() and REPLACE()

Take a look : FIDDLE

select IF((TRIM(replace(' IKECHUKWU  OSUJI',' ',''))=TRIM(replace('IKECHUKWU OSUJI',' 
',''))),"same","diff");
select IF((TRIM(replace(' Aman Minhas  ',' ',''))=TRIM(replace(' Aman Min has',' 
',''))),"same","diff");

Err image The first query returns diff. The second returns same. Its some weird spacing issue, cant seem to understand why this behaviour.

Upvotes: 1

Views: 7305

Answers (1)

Ed Gibbs
Ed Gibbs

Reputation: 26353

Your first string has a tab in it:

select IF((TRIM(replace(' IKECHUKWU  OSUJI',' ',''))
                                   ^ this is actually a tab in the Fiddle

You can get rid of it with an additional REPLACE:

REPLACE(REPLACE(myString, ' ', ''), '\t', '')

The \t is a special literal. Other special literals such as newline or ASCII NUL may impact you as well. Literals are listed here.

Upvotes: 5

Related Questions