1

MOrris Example

Morris.Bar({
  element: 'bar-example',
  data: [
    { month: "2006", amount: 100},
    { month: "2007", amount: 75}
  ],
  xkey: "month",
  ykeys: ["amount"],
  labels: ["amount"]
});

amount in ykeys and lables should be same as it is mentioned in Morris Example. Otherwise graph would not display because of error in amount format.

At moment my amount value is in this way

String amount = "[amount]";

amount="[amount]"

and i want value in this way

["amount"]

What would be easiest and preferred way to replace these values?

2
  • I think you can parse amount first using JSON.parse(), so you will get an array of strings, from where you can pick "amount" by using amountArray[0] Commented Dec 23, 2016 at 12:07
  • Why do you use String when amount is an array? String amount="[amount]"; is written by you or come like a string from another service that you can't touch? Commented Dec 24, 2016 at 8:12

2 Answers 2

3

Why regex?

If you can achieve your task with simple calls to APIs which don't require regex, stick to them.

amount.subString(1,amount.length()-1);
Sign up to request clarification or add additional context in comments.

6 Comments

amount.substring(1,amount.length - 1); in javascript
@Milaci Really!! ??
If Tatkal need to replace it on front-end. What really? For substring in js?
He didn't add javascript tag.
Ah ok, i didn't see that. I see only json and i thinked that was for some front-end stuff. Some ajax ..
|
1

You don't need to use regex.

  amount = amount.replace("[", "[\"").replace("]","\"]");

Edited. OP cleared up what was needed. The above code is replacing [ with [" and ] with "].

The " is escaped within java with \

1 Comment

i get output as amount. it should be in this way ["amount"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.