-1
$\begingroup$

What pattern should i give to the following expression

("146d0" A + "-594d0" B)

so i would get

("146d0" A - "594d0" B)
$\endgroup$
  • 2
    $\begingroup$ Before we get into XY problem solving, what are you trying to achieve? $\endgroup$ – Roman Nov 21 at 20:58
  • 1
    $\begingroup$ What's the point of this question and answer? It makes no sense. $\endgroup$ – user6014 Nov 21 at 21:39
2
$\begingroup$
("146d0" A + "-594d0" B) /. s_String?(StringStartsQ["-"]) :> -StringDrop[s, 1]

(*    "146d0" A - "594d0" B    *)
$\endgroup$
-1
$\begingroup$

This pattern seems to be working

("146d0" A + "-594d0" B) //. 
 Times[A_String, 
   B_] :> -StringDelete[ToString[-ToExpression[A]], " "] B /; 
   Negative[First@ToExpression[A]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.