base64 - Javascript - replacing a certain amount of characters in a string and leaving the rest -
this weird question.
essentially, thought cool thought allow user type string, have string converted base64, , create image.
although i'm not learned in base64, know images have header data, , need length. i've managed separate base64 info tells colors of image. right now, have basic white image - you can check js fiddle here - (not sure if it's working there, works in browser).
anyway, variable "imgdata" raw info png image, , that's i'd change. unfortunately, string seems need amount of characters, or image won't work (guessing it's size specified in header?)
because unlikely user inputted string reach same number of characters when converted base64, know how replace first part of string, , leave rest alone.
tl;dr
i have string -
aaa
and want replace string -
123456
since string1 3 characters, want replace first 3 characters of string2 outcome like
aaa456
remember string1 vary in length.
create string containing default values:
var fulllength = "abcdefg";
get user input string:
var user = "aaa";
create 3rd string combination of user info , end of default:
var combined = user + fulllength.substring(user.length);
because javascript weakly typed language, need ensure working string objects. can concatenating empty string create sure of string functions work:
var userstring = userinput + "";
also, there 3 similar string functions, slice()
, substr()
, , substring()
. research on mdn see best you.
javascript base64
No comments:
Post a Comment