This is a weird question.
Essentially, I thought it would be a cool idea to let a user type a string, have that string converted to base64, and create an image.
Although I'm not learned in base64, I know images have header data, and need to be a certain length. I've managed to separate the base64 data that tells the colors of the image. Right now, I have a basic white image - you can check a js fiddle here - (not sure if it's working there, but it works in my browser).
Anyway, the variable "imgdata" is the raw data for my PNG image, and that's what I'd like to change. Unfortunately, that string seems to need a certain amount of characters, or the image won't work (guessing it's a size specified in the header?)
Because it is unlikely that a user inputted string will always reach that same number of characters when converted to base64, I would like to know how to replace the first part of a string, and leave the rest alone.
TL;DR
I have this string -
aaa
and I want to replace this string -
123456
Since string1 is only 3 characters, I only want it to replace the first 3 characters of string2 so the outcome would look like
aaa456
remember that string1 will vary in length.