bool trim_strcmp(const char* s1, const char* s2) { if (s1 == s2) { return true; } if ((NULL == s1) || (NULL == s2)) { return false; } int s_s1 = -1; int e_s1 = strlen(s1); int c_s1 = 0; int s_s2 = -1; int e_s2 = strlen(s2); int c_s2 = 0; int blank = ' '; while (*(s1 + ++s_s1) == blank); while (*(s2 + ++s_s2) == blank); //全是空格 if ((s_s1 == e_s1) && (s_s2 == e_s2)) { return true; } while (*(s1 + --e_s1) == blank); while (*(s2 + --e_s2) == blank); c_s1 = e_s1 - s_s1 + 1; c_s2 = e_s2 - s_s2 + 1; return (c_s1 == c_s2)?(0 == strncmp(s1 + s_s1, s2 + s_s2, c_s1)):false; }
测试结果: