如何将两个字符串连接成base64字符串

huangapple go评论72阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2023年7月6日 18:52:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定