This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
If I have a string "__this__is_not__easy_" How do I get the length of the first word and cut the rest of the string into equal length peaces like this. (_ = space) __this___is___not_easy_ result should be: this is_n ot_e asy_
MacTosh-- I'm unclear on the rules that apply to breaking up your input string, "~~this~~is~not~~easy~", where "~" stands for a space. So I'll proceed on the assumptions I've gleaned from answers to these questions: 1) Do the leading spaces (here, the two before "this") count in the length of the first word? 2) Does the first word end with the "s" in "this" or with the last space before "is"? 3) If there are multiple spaces between words, should they be included in the pieces of the string as well? It would seem from the problem as you've described it that the answers to these questions would be "No", "the 's' in 'this'", and "No". If these assumptions are correct, then you need to: A. Remove all duplicate spaces from your input string, so that "~~this~~is~not~~easy~" would become "this~is~not~easy". B. Get the length of the first string. C. Use the substring() method in a loop to return pieces of the string that are as long as the value in B, making sure that the first character of the substring is not a space, and indexing accordingly. Hope this helps, MacTosh. Art