Lexicographically smaller string among two strings

String s=s1s2…sn is lexicographically smaller than string t=t1t2…tm if n<m and s1=t1,s2=t2,…,sn=tn or there exists a number p such that p≤min(n,m) and s1=t1,s2=t2,…,sp−1=tp−1 and sp<tp.
For example, “aaa” is smaller than “aaaa”, “abb” is smaller than “abc”, “pqr” is smaller than “z”.

if(lenA == lenB) // then check according to ascii value
if(lenA > lenB) // then comparing string A and B till length of the B
else // compare till the length of strign A