Posted December 22, 200717 yr Is there anyone in here who could help me with this little problem here:I have a string of 30 chars, I want to divide that string into 3 lines with 10 chars at max per line.Only problem is; NO WORDS SHOULD BE DIVIDED INTO 2 PARTS, it must stop and choose next lineif it see that the word is too long for the line....What I have so far:String[] Splitter = input.Split(new char[] { ' ' });That code will then split the string into bits and parts, now to the rebuilding part where the actual help I need is needed.... Any good and valid suggestions?/Regards, n00b
December 22, 200717 yr Um.. I think, you need to hardcode it.For example like this: private void tbxInput_TextChanged(object sender, EventArgs e) { string[] Input = tbxInput.Text.Split(' '); int Position = 0; tbxOutput1.Text = Split2Array(Input, ref Position); tbxOutput2.Text = Split2Array(Input, ref Position); tbxOutput3.Text = Split2Array(Input, ref Position); } private string Split2Array(string[] IN, ref int POS) { string Split = ""; string OUT = ""; while ((Split.Length <= 10) && (POS < IN.Length)) { Split += IN[POS]; if (Split.Length > 10) break; OUT = Split; POS++; } return OUT; }But it leaves out the spaces between the words..
December 22, 200717 yr Author Thx for the reply UFO, but its still more efficient to use my old procedure than using yours im afraid
Create an account or sign in to comment