Click to See Complete Forum and Search --> : string characters


jrthor2
04-04-2007, 10:29 AM
I have a string that I generate that has 5 characters (for a captcha implementation). I'm implementing a new flash based captcha, and what I need to do is pass each character in my string into my class, for example:

String capText = captchaProducer.createText();
new Invoker(1,'character1', 'character2', 'character3', 'character4', 'character5')

How can I take capText and get each character for my Invoker class? The individual characters need to be of type char as well.

Thanks.

AlaNio
04-04-2007, 02:41 PM
read string api. I'm pretty sure theres a substring function or something that allows you extract part of a string.

sae
04-05-2007, 03:47 PM
string extract

http://tomcat.apache.org/tomcat-4.1-doc/catalina/docs/api/org/apache/catalina/util/StringParser.html#extract(int,%20int)

jrthor2
04-05-2007, 03:49 PM
I got this working by doing:

String capText = captchaProducer.createText();
capText.charAt(0)
capText.charAt(1)
capText.charAt(2)
capText.charAt(3)

agent_x91
04-15-2007, 03:30 PM
Indeed, getting a single character from a String is done by using the method

String.charAt(int index);

Other useful string manipulation methods include split, indexOf, matches, and replaceAll/replaceFirst.