The output of the line with speed

I apologize if I am waffles or say a little skepticism, but I'm new to speed and these forums!

I need to check the contents of a string for a specific character and print the second part of the text if it appears. For example:

set ($string = "This is a long string *** but I only want to output this on my email"). 

I want to display all text after 3 stars. I looked through the forums, but could not find anything that would help me completely.

+7
source share
1 answer

Velocity is just a facade for real Java objects, so you have access to all the public methods of the String class , including indexOf and substring . So try something like:

 #set ($string = "This is a long string *** but I only want to output this on my email") #set ($index = $string.indexOf('***')) #set ($index = $index + 3) #set ($end = $string.substring($index)) 

If you have more control over the objects that you put in context, you can add an instance of StringUtils as a helper tool, and then use substringAfter .

+20
source

All Articles