I've done something similar in the past, but it requires that you manually do the template merge field lifting. Here is an example of how you could do it below.
Since you are manually doing the merging in the template, you can put any kind of merge field into your template that you'd like. In this example, I'm pretending there is a custom merge field {!myCustomString} in the email template for your custom string you want to insert.
I've also assumed below that you have a merge field for first name {!Contact.FirstName} in the subject and in the body of the template. If you have other fields, you would need to include the fields in the contact query and then to the string replace for each of those fields.
public static void sendSingleMail(Id contactId, Id templateId, String fromAddress, String myCustomString){
// grab the email template
EmailTemplate emailTemplate = [select Id, Subject, HtmlValue, Body from EmailTemplate where Id =: teamplateId];
// grab the contact fields we need. This assumes we are emailing a contact.
Contact c = [Select Id, FirstName FROM Contact WHERE Id=: contactId];
// process the merge fields
String subject = emailTemplate.Subject;
subject = subject.replace('{!Contact.FirstName}', c.FirstName);
String htmlBody = emailTemplate.HtmlValue;
htmlBody = htmlBody.replace('{!Contact.FirstName}', c.FirstName);
htmlBody = htmlBody.replace('{!myCustomString}', myCustomString);
String plainBody = emailTemplate.Body;
plainBody = plainBody.replace('{!Contact.FirstName}', c.FirstName);
plainBody = plainBody.replace('{!myCustomString}', myCustomString);
//build the email message
Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();
email.setReplyTo(fromaddress);
email.setSenderDisplayName(fromaddress);
email.setTargetObjectId(objId);
email.setSaveAsActivity(true);
email.setSubject(subject);
email.setHtmlBody(htmlBody);
email.setPlainTextBody(plainBody);
Messaging.sendEmail(new Messaging.SingleEmailmessage[] {email});
}
The format method automatically does the commas and periods or visa versa (depending on whether your profile is in the US or elsewhere)
Assuming the $ sign applies to all cases in your org you can simply use
Decimal input = 2000;
String output = '$' + String.valueOf(input.format());
Note the String.valueOf(). This is required because the input variable is defined as a Decimal.
Edit:
I noticed a bug with the Decimal.format() method where it will not show any numbers past the decimal point if there are only zeros there, ex. $100.00. To solve this I came up with this method.
private String getCents(Decimal x){
String y = String.valueOf(x);
String z = '.';
if(y.contains(',')) z = ',';
y = y.substring(0, y.indexOf(z));
if(x - Decimal.valueOf(y) == 0)
return String.valueOf(x.format()) + z + '00';
else return String.valueOf(x.format());
}
Then to update the example above, it would be:
Decimal input = 2000;
String output = '$' + getCents(input);
Best Answer
I ended up using JSON to parse it:
I had to use a Map of String, Object for some reason even though it's technically a Map. I just have to cast the result to a String whenever I get the value.