Last post May 14, 2012 05:29 AM by Paul Linton
May 11, 2012 06:00 PM|gdreedy|LINK
Need help to split string to get List<string> at spaces if the string lenth is >12. words should not be breaked. sub strings should be length <12
string = "asp.net is a Web app framework developed a"
substrings in the list should be : asp.net is a, Web app, framework, developed a.
May 11, 2012 06:26 PM|gerrylowry|LINK
TIMTOWTDI =. there is more than one way to do it
one approach that comes to mind, in pseudo-code, is this.
(a) create List<String> or String workingList as the set of non empty strings from your input string
http://msdn.microsoft.com/en-us/library/b873y76a.aspx "String.Split Method (Char)"
(b) have a List<string> result_strings with zero entries
(c) have a String that is empty
(d) foreach through the workingList ... keep adding parts to the empty string as long as it will not exceed 11 bytes in length
(e) if the next part will exceed length == 11, add the current part to your result_strings and start your next part with your String from (c) set back to String.Empty..
(f) watch for the special case where any individual part is >= 11 bytes.
(g) remember to append a space between all concatenated parts.
P.S.: just curious, is this a homework assignment?
May 14, 2012 05:29 AM|Paul Linton|LINK
sub strings should be length <12
but your first output is 12 characters long. Is the specification correct or your sample?