英文:
How to concatenete 2 String to base64 String
问题
You can concatenate two strings to a Base64 string like this:
const base64basic = "data:image/png;base64,";
const base64back = JSON.stringify(dataNew.base64Img);
const base64picture = base64basic.concat(base64back);
console.log(base64picture);
However, it seems there are "
in the resulting string, which should not be there.
英文:
How can i concatenete 2 Strings to Base64 String?
Ive tried this:
const base64basic = "data:image/png;base64,";
const base64back = JSON.stringify(dataNew.base64Img);
const base64picture = base64basic.concat(base64back)
console.log(base64picture)
dataNew.base64Img
is my Base64 String:
iVBORw0KGgoAAAANSUhEUgAAAEAAAAAwCAYAAAChS3wfAAAAAXNSR0IArs4c6QAAASFJREFUaEPtmsEOxCAIRAf3//94Ixu8CySkQbfTSw/VpLwOA2pljKFougTAZwJ2310i+6cqwBeKSgDSDkABcSL4ewCmPw+AJ05TwBTcrQAL3ksB1b081pMhlwOwIJwU8AAsddwOIPJfnZ5BAOYR15qgBe/JP4ITiCczHa1VIPWGDw86HkDkAV6ZzLAjgM5GKPOFqACnD1gm6rTKGcBMAaZA42owI1F6AD3Ab3RpgqwCtdUEyyDLIMtg364w+4AEgdc3QglGpSHHV4FSdInJBHB6GUx8xNIQKoAKOLwRKuk7MZkpwBRgCpy9FkikcWkIPYAeQA+gB1R+sCgZ0AmT200w2vCIIF1/LkAAwdEXFRAQYAqUjsak/y+xXg94PYBBBfwA5wWZJstGb8AAAAAASUVORK5CYII=
After concatenetion
i get the output in console this:
data:image/png;base64,"iVBORw0KGgoAAAANSUhEUgAAAEAAAAAwCAYAAAChS3wfAAAAAXNSR0IArs4c6QAAASFJREFUaEPtmsEOxCAIRAf3//94Ixu8CySkQbfTSw/VpLwOA2pljKFougTAZwJ2310i+6cqwBeKSgDSDkABcSL4ewCmPw+AJ05TwBTcrQAL3ksB1b081pMhlwOwIJwU8AAsddwOIPJfnZ5BAOYR15qgBe/JP4ITiCczHa1VIPWGDw86HkDkAV6ZzLAjgM5GKPOFqACnD1gm6rTKGcBMAaZA42owI1F6AD3Ab3RpgqwCtdUEyyDLIMtg364w+4AEgdc3QglGpSHHV4FSdInJBHB6GUx8xNIQKoAKOLwRKuk7MZkpwBRgCpy9FkikcWkIPYAeQA+gB1R+sCgZ0AmT200w2vCIIF1/LkAAwdEXFRAQYAqUjsak/y+xXg94PYBBBfwA5wWZJstGb8AAAAAASUVORK5CYII="
There are "
in the String, which should not there.
答案1
得分: 2
JSON.stringify
会引用字符串,所以您不需要它:
const base64picture = "data:image/png;base64," + dataNew.base64Img;
console.log(base64picture);
英文:
JSON.stringify
quotes string, so you don't need it:
const base64picture = "data:image/png;base64," + dataNew.base64Img;
console.log(base64picture);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论