n00b!ICU Posted December 22, 2007 Posted December 22, 2007 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
Ufo-Pu55y Posted December 22, 2007 Posted December 22, 2007 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..
n00b!ICU Posted December 22, 2007 Author Posted December 22, 2007 Thx for the reply UFO, but its still more efficient to use my old procedure than using yours im afraid
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now