text split up!
-
Guys, I send to a webservice a gift message string which can be any length. That service splits the string into 30 characters and creates a new line. example: I type: Hi Jocey!! I Hope you have a stupendous 30th birthday! I'm aorry I can't make it! Suexoxo The web service splits as follows: Hi Jocey!! I Hope you have a s tupendous 30th birthday! I'm s orry I can't make it! Suexoxo My question is, can we do something like this, if the break happens to be in a word like S orry can we fill up with spaces and send that sorry next line. I am unclear please follow up. may be some regular expression? Thank you very much for your help guys!
-
Guys, I send to a webservice a gift message string which can be any length. That service splits the string into 30 characters and creates a new line. example: I type: Hi Jocey!! I Hope you have a stupendous 30th birthday! I'm aorry I can't make it! Suexoxo The web service splits as follows: Hi Jocey!! I Hope you have a s tupendous 30th birthday! I'm s orry I can't make it! Suexoxo My question is, can we do something like this, if the break happens to be in a word like S orry can we fill up with spaces and send that sorry next line. I am unclear please follow up. may be some regular expression? Thank you very much for your help guys!
Yes you can. Find all instances of the space character in your long string. Then only send strings based on the space not based on the character position. You can then add padding to the end if necessary.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego. -
Guys, I send to a webservice a gift message string which can be any length. That service splits the string into 30 characters and creates a new line. example: I type: Hi Jocey!! I Hope you have a stupendous 30th birthday! I'm aorry I can't make it! Suexoxo The web service splits as follows: Hi Jocey!! I Hope you have a s tupendous 30th birthday! I'm s orry I can't make it! Suexoxo My question is, can we do something like this, if the break happens to be in a word like S orry can we fill up with spaces and send that sorry next line. I am unclear please follow up. may be some regular expression? Thank you very much for your help guys!
Use the LastIndexOf method to find the last space within the first 30 characters and split the string there. Use the PadRight method to add spaces. Example:
string msg = "Hi Jocey!! I Hope you have a stupendous 30th birthday! I'm aorry I can't make it! Suexoxo";
List lines = new List();
while (msg.Length > 30) {
int pos = msg.LastIndexOf(' ', 29, 30);
if (pos != -1) {
lines.Add(msg.Substring(0, pos).PadRight(30));
msg = msg.Substring(pos + 1);
} else {
lines.Add(msg.Substring(0, 30));
msg = msg.Substring(30);
}
}
lines.Add(msg.PadRight(30));foreach (string s in lines) Console.WriteLine("\""+s+"\"");
Despite everything, the person most likely to be fooling you next is yourself.
-
Use the LastIndexOf method to find the last space within the first 30 characters and split the string there. Use the PadRight method to add spaces. Example:
string msg = "Hi Jocey!! I Hope you have a stupendous 30th birthday! I'm aorry I can't make it! Suexoxo";
List lines = new List();
while (msg.Length > 30) {
int pos = msg.LastIndexOf(' ', 29, 30);
if (pos != -1) {
lines.Add(msg.Substring(0, pos).PadRight(30));
msg = msg.Substring(pos + 1);
} else {
lines.Add(msg.Substring(0, 30));
msg = msg.Substring(30);
}
}
lines.Add(msg.PadRight(30));foreach (string s in lines) Console.WriteLine("\""+s+"\"");
Despite everything, the person most likely to be fooling you next is yourself.
-
your anser works like a miracle. one more question for you. how can I clean up the text from carriage returns and line feeds? before starting the process? please advice.