java - how to format string as my expectation in android? -
suppose have string that
string s= " %k%%m%r%"; now want string formatted as
"k%m%r" means white spaces removed beginning , end point, if starts or ends % % removed , in middle if % remains sequentially more 1 reduced 1 %.
how can that?
string pattern = "(%+)"; string exclude = "(^%*)|(%*$)"; string candidate = "%k%%%m%%%%%r%"; system.out.println(candidate.trim().replaceall(exclude,"").replaceall(pattern, "%")); produce: k%m%r
Comments
Post a Comment