Help with function that automatically insert newline character after 32 characters.

I developed notification system using sarge manager from bootcamp but there is a problem i have to insert newline character manually. is there function that can do it manually?

Here is one way to do it:

function InsertNewlines(str : String){
	var newText = "";
    for (i=0;i<str.length;i++){
    	newText += str[i];
    	if ((i+1) % 32 == 0)
    	    newText += "\n";	
    }
    return newText;
}

good thought of using modulo operator. i done the same thing using split but it was slow. thanks for reply. god bless you.

My solution for problem is here.

Solution 1 :-

function formatInstruction(instruction : String)
{
            var newText = ""; 
	    for (i = 0; i < instruction.length; i++)
            {
	        newText += instruction[i];
	        if ((i + 1) % 32 == 0)
                {
	            newText += "\n";
                }
            }
	    newText = newText.Replace("\n ", "\n");
	    return newText;
}

Solution 2 :-

	function formatInstruction(instruction : String)
	{
		var newInstruction = "";
		var length : int = 0;
		var spaceCounter : int = 0;
		var strSplit : String[] = instruction.Split(" "[0]);
		for (var i : int = 0; i < strSplit.Length; i++)
		{
			if (length + strSplit[i].Length > (32 - spaceCounter))
				newInstruction += strSplit[i];
			else
				newInstruction += strSplit[i] + " ";
				spaceCounter++;
			length += strSplit[i].Length;
			if((i + 1) < strSplit.Length)
			{
				if (length + strSplit[i].Length > (32 - spaceCounter))
				{
					length = 0;
					spaceCounter = 0;
					newInstruction += "\n";
				}
			}
		}
		return newInstruction;
	}

I’m using solution 2 so words aren’t broken in to two lines.:sunglasses::sunglasses::sunglasses: