Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:19:46+00:00 2026-06-03T02:19:46+00:00

I’ve got a strange problem using the Castle NVelocity… If the template string ends

  • 0

I’ve got a strange problem using the Castle NVelocity…

If the template string ends with a $ character, it throws the following and exception:

Lexical error: NVelocity.Runtime.Parser.TokenMgrError: Lexical error
at line 1, column 94. Encountered: after : “”

If i add a space, or any other character, to the end of the string it works as expected.

Does anybody have a workaround for this?

Here’s some sample code that reproduces the problem:

class Program
{
    static void Main(string[] args)
    {
        var result = Merge("The quick brown ${Animal} jumps over the lazy dog$", new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("Animal", "fox") });

        Console.WriteLine("Success: {0}", result.Key);
        Console.WriteLine("Message: {0}", result.Value);
        Console.Read();
    }

    public static KeyValuePair<bool, string> Merge(string template, IList<KeyValuePair<string, string>> data)
    {
        var ret = new KeyValuePair<bool, string>(false, null);
        try
        {
            if (data != null)
            {
                var engine = new VelocityEngine();
                engine.Init();

                var context = new VelocityContext();
                foreach (var tokenData in data)
                {
                    context.Put(tokenData.Key, tokenData.Value);
                }

                var templateContent = template;

                var sb = new StringBuilder();
                var textWriter = new StringWriter(sb);

                engine.Evaluate(context, textWriter, String.Empty, templateContent);

                ret = new KeyValuePair<bool, string>(true, sb.ToString());
            }
        }
        catch (Exception ex)
        {
            ret = new KeyValuePair<bool, string>(false, ex.Message);
        }
        return ret;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:19:49+00:00Added an answer on June 3, 2026 at 2:19 am

    You have a couple of options:

    If you have no influence over the input string to be merged, make sure that they don’t have a trailing dollar character, at least not for the merge process:

    Example:

    bool dollarAtEnd = false;
    
    if (input.EndsWith('$'))
    {
       input += " "; 
       dollarAtEnd = true;
    }
    
    var result = Merge(input, ...);
    
    if (dollarAtEnd)
    {
       result = result.Substring(1, result.Length - 1);
    }
    

    If you can control the input string, but only have the requirement that some of them should end with a dollar character, you can do as follows:

    Example:

    "#set($dollar='$')The quick brown ${Animal} jumps over the lazy dog$dollar"
    

    Or pass “dollar” as variable to the VelocityContext, rather than specifying it inline.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.