Overcoming Maximum Console Post Size

Trevor being Trevor's icon

I ran into a situation while testing a Max project where I needed to post a string bigger than what the post() function / Max Console output allows. I figured I would post the solution I used to help anyone else out there. The console seems to have issues somewhere between 2000 and 3000 characters. I used a maxSize of 2000 characters and that works well enough for me. Use the testing function with smaller strings to get an idea of how it works. This is super niche, but hopefully it will help somebody out there!

function MaxConsoleStringSlicerTesting(str, maxSize){
    post("Original String: " + str + "\n");

    var amountToSplit = Math.floor(str.length / maxSize);
    post("String Length: " + str.length + "\n");
    post("Max Characters Per Split: " + maxSize + "\n");
    post("Amount To Split: " + amountToSplit + "\n");

    //if the string is within the limit
    if(amountToSplit < 1){
        post("String Did Not Need to Be Split: " + str + "\n");
    } else {

        if(amountToSplit == 1){
            var substringLength = Math.floor(str.length/2);
        } else {
            var substringLength = Math.floor(str.length/amountToSplit);
        }
        
        post("SubString Length: " + substringLength + "\n");
        for(var i = 0; i < amountToSplit; i++){

            if(i < (amountToSplit - 1)){
                post("Split " + (i + 1) + " : " + str.substring((substringLength * i), (substringLength * (i + 1))) + "\n");
            } else {
                post("Split " + (i + 1) + " : " + str.substring((substringLength * i), (substringLength * (i + 1))) + "\n");
                if((substringLength * (i + 1)) < str.length){
                    post("Remainder : " + str.substring((substringLength * (i + 1)), str.length) + "\n");
                }
            }
        }
    }
}

function MaxConsoleStringBreaker(str, maxSize){
    var amountToSplit = Math.floor(str.length / maxSize);

    //if the string is within the limit just post it
    if(amountToSplit < 1){
        post(str);

    //otherwise seperate it out
    } else {
        if(amountToSplit == 1){
            var substringLength = Math.floor(str.length/2);
        } else {
            var substringLength = Math.floor(str.length/amountToSplit);
        }

        for(var i = 0; i < amountToSplit; i++){

            //if it's not the last iteration
            if(i < (amountToSplit - 1)){
                post("(--MAX POST DIVIDER--)")
                post(str.substring((substringLength * i), (substringLength * (i + 1))));

            //otherwise for the last iteration
            } else {
                post("(--MAX POST DIVIDER--)")
                post(str.substring((substringLength * i), (substringLength * (i + 1))));

                //check if the entire string has been covered
                if((substringLength * (i + 1)) < str.length){
                    post("(--MAX POST DIVIDER--)")
                    post(str.substring((substringLength * (i + 1)), str.length));
                }
            }
        }
    }
}