0

I want to get it after "data: application / vnd.openxmlformats-officedocument.wordprocessingml.document; base64,". I want to pull the data starting with "UEsDBBQACAgIANBmkE8AAAAA ...". How can I do that?

Base64 output

ADDENDUMA: "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,UEsDBBQACAgIANBmkE8AAAAAAAAAAAAAAAALAAAAX3JlbHMvLnJlbHOt0sFKAzEQBuB7n2KZe3e2VURks72I0JtIfYCQzO4Gm0xIplrf3lAKulBWwR4z+efnI6TdHP2+eqeUHQcFq7qBioJh68Kg4HX3tLyHTbdoX2ivpUTy6GKuyk7ICkaR+ICYzUhe55ojhXLTc/JayjENGLV50wPhumnuMP3sgG7SWW2tgrS1K6h2n5H+

React JS

if(convertedResult){
    props.values.addendumA = convertedResult
    props.values.addendumA = JSON.stringify(props.values.addendumA)
    console.log('ADDENDUMA: '+props.values.addendumA)
    changeSelectedA(props.values.addendumA)
}
meren
  • 432
  • 5
  • 19

2 Answers2

1

You can use a simple Regex expression

const regex = '(.*)(base64,)(.*)';
var macthes = props.values.addendumA.match(regex);
var val = macthes[3]; //This is what you're looking for
Lewis Johnson
  • 330
  • 4
  • 15
  • No need to capture the first part if all that's cared about is after the `base64,`. I'd also recommend just using an immediate regex rather than converting a string. – Dave Newton Apr 27 '20 at 14:50
-1

You can split using base64,, remove the first element and then join again.

let parts = addendumA.split("base64,")
parts.shift()
parts.join("")
Radu Diță
  • 13,476
  • 2
  • 30
  • 34
  • 1
    Please don't answer obvious duplicates. – Heretic Monkey Apr 27 '20 at 14:44
  • if it's a duplicate it will get closed as such – Radu Diță Apr 27 '20 at 14:45
  • 1
    If it's a duplicate, you should be voting to close it as such, not making it harder to do so. – Heretic Monkey Apr 27 '20 at 14:46
  • 1
    This may not be the right place to have this discussion, but I don't see how answering can make it harder to close it as a duplicate. I could even argue that the proposed duplicate, although answering a more general problem, does not answer this particular question. Some people may reach this page looking for exactly how to get the base64 repr from an img source and this could be faster and easier for them. – Radu Diță Apr 27 '20 at 14:49
  • 1
    @RaduDiță When a general solution answers a specific question the general solution should be preferred. Regexes/substrings/etc. are trivially searchable; that this is searching for a specific string is immaterial. – Dave Newton Apr 27 '20 at 14:56
  • There is plenty of debate as to the worth of answering duplicates on Meta Stack Overflow. See [Should there be a deterrent for answering obvious duplicate questions?](https://meta.stackoverflow.com/q/252009/215552) and [Delete an Answer if Duplicate Found After Posting?](https://meta.stackoverflow.com/q/266551/215552) – Heretic Monkey Apr 27 '20 at 16:08