Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Converting to uppercase using Perl5Substitution

Reply
Thread Tools

Converting to uppercase using Perl5Substitution

 
 
Sudeep Batra - Bond 007
Guest
Posts: n/a
 
      04-07-2004
Hi,

We are using the following piece of code for Perl5Substitution.

public String substitute (String regExp, String sub, String input)
throws DatafileException {
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler compiler = new Perl5Compiler();
try {
pattern = compiler.compile(regExp);
} catch(MalformedPatternException e){
String errorMessage = "Bad pattern. " + e;
log.error(errorMessage);
throw new DatafileErrorException(errorMessage);
}
// Perform substitution
return Util.substitute(matcher, pattern, new
Perl5Substitution(sub, 0),input,99);
}

Lets say we want to convert a string such that every word should begin
with "A", then if we pass the following values as parameters to the
above, it works for us.

regExp = (\w+)
sub = A$1

This converts a string "Preferred Stock" to "APreferred AStock".

However, we are not able to find a way to convert the string to
uppercase. The following regular expression in perl script works fine
for us.
$variable=~ s/(\w+)/uc($1)/ge;

But we are not able to reproduce the same to work with
Perl5Substitution. \U doesnt seem to work even.

If anyone can suggest what we should pass as the regular expression
and the substitution string so that we get the desired, that would be
really appreciated.

Thanks
Sudeep
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      04-07-2004
On 6 Apr 2004 17:22:08 -0700, Sudeep Batra - Bond 007 wrote:

> We are using the following piece of code for Perl5Substitution.


What a coincidence, so is some guy over
on c.l.j.help. Maybe you should get in
contact with him, he might have the answer.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
uppercase ASP .Net 1 02-20-2006 05:23 AM
turn uppercase on in controls Beffmans ASP .Net 1 08-02-2005 01:59 PM
Converting string to uppercase using Perl5Substitution Sudeep Batra - Bond 007 Java 2 04-08-2004 10:52 AM
Converting form field data to uppercase Nige Javascript 7 11-17-2003 10:01 PM
converting asp:textbox to uppercase Ruby ASP .Net 1 07-31-2003 04:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57