template string question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

template string question

Liu, Teh P
Hi All,

I have a string "TehpaoLiu"

Is it possible to just extract "Tehpao" from the above string in velocity?

Any help will be appreciated.

Thanks

- tehpao
Reply | Threaded
Open this post in threaded view
|

Re: template string question

Adam Williams
On 5/25/05, Liu, Teh P <[hidden email]> wrote:
> I have a string "TehpaoLiu"
> Is it possible to just extract "Tehpao" from the above string in velocity?

That is a very vague question, but I suppose that since you know the
value of the String, you know the start and end index of the
characters that you want.

$yourstring.substring(0, 6)

Or, you can just write "Tehpao"...

 adam

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: template string question

Barbara Baughman
In reply to this post by Liu, Teh P
Since Velocity is using Java, you have access to all of the public
methods of the classes in the java.lang package. String methods are
included.

#set ($string="TehpaoLiu")
$string.substring(0,6)

Barbara Baughman
X2157

On Wed, 25 May 2005, Liu, Teh P wrote:

> Hi All,
>
> I have a string "TehpaoLiu"
>
> Is it possible to just extract "Tehpao" from the above string in velocity?
>
> Any help will be appreciated.
>
> Thanks
>
> - tehpao
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: template string question

apache-10
In reply to this post by Liu, Teh P
if you are using Java1.4 to run the veolicty application, consider
using the regular expression capabilities of the String class:

#set( $string = "TehpaoLiu" )
#if( $string.matches("[a-z][A-Z]") )## or $string.substring(1).matches("[A-Z]")
   #set( $string = $string.replaceAll("[A-Z][a-z]+$", "") )
#endif

See the APIdoc for the String and java.util.regex.Pattern classes
for more information.

Cheers,
:) Christoph Reck


Liu, Teh P wrote:

> Hi All,
>
> I have a string "TehpaoLiu"
>
> Is it possible to just extract "Tehpao" from the above string in velocity?
>
> Any help will be appreciated.
>
> Thanks
>
> - tehpao
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]