shragi
asked on
textarea string
I had a textarea field and I stored the value from textarea into string...
i pasted huge data into textarea...
using servlets i stored
String storetxtarea = req.getParameter("textarea variable")
now i had two problems...
1)I heard that get method gets maximum 1k how about huge data should i use Post method
2. suppose i had data less than 1k and stored in string how do i get to the end of the string.
should i use while(storetxtarea.equals( "\n");
wat if i post multiple lines of data in text area then the above condition fails..
so anyideas for above 2 problems..
i pasted huge data into textarea...
using servlets i stored
String storetxtarea = req.getParameter("textarea
now i had two problems...
1)I heard that get method gets maximum 1k how about huge data should i use Post method
2. suppose i had data less than 1k and stored in string how do i get to the end of the string.
should i use while(storetxtarea.equals(
wat if i post multiple lines of data in text area then the above condition fails..
so anyideas for above 2 problems..
when you use String s = req.getParameter("textarea varaible")
your String s gets all its lines witin it, including end of lines
between them
You can then
set up InputStream in = new InputStream(new ByteArrrayInputStream(s.ge ttBytes())
and read this text as if you are reading lines
from file - so if you need only first line you can read only first line
About totla of 1K in textara - don't kniow - haven't heard about it
seems to be a hard constraint
your String s gets all its lines witin it, including end of lines
between them
You can then
set up InputStream in = new InputStream(new ByteArrrayInputStream(s.ge
and read this text as if you are reading lines
from file - so if you need only first line you can read only first line
About totla of 1K in textara - don't kniow - haven't heard about it
seems to be a hard constraint
Oh yes, about get and post - I misunderstood,
I thought you meant overall limitations.
Surre of course use post for big chunks of data
I thought you meant overall limitations.
Surre of course use post for big chunks of data
>>wat if i post multiple lines of data in text area then the above condition fails..
The linefeeds will be included inside the String
The linefeeds will be included inside the String
ASKER
data in textarea:
"hi hello
bye
how are you
eureka
i am fine"
so, when I use
String str = req.getParameter("textarea varaible")
I had my entire string in str
and i want to search for somestring "eureka" in the str
if I search while(str.equals("\n"))
then I will not find eureka becoz the while loop stops at "bye"
how can I search till end...
and is the below syntax correct
String storetxtarea = req.postParameter("textare avariable" )
"hi hello
bye
how are you
eureka
i am fine"
so, when I use
String str = req.getParameter("textarea
I had my entire string in str
and i want to search for somestring "eureka" in the str
if I search while(str.equals("\n"))
then I will not find eureka becoz the while loop stops at "bye"
how can I search till end...
and is the below syntax correct
String storetxtarea = req.postParameter("textare
you can just search
storetextarea.indexOf("eur eka") then at least
your "eureka" is broken by the end of line
you'll find it.
If you want to find it even if it is broken by the end of line then you probably
want to do it with regular expressions
If you know that it is not broken then indexOf will return you the indedex of the charcter across the whole string where it begins
or -1 if there is no "ereka"
storetextarea.indexOf("eur
your "eureka" is broken by the end of line
you'll find it.
If you want to find it even if it is broken by the end of line then you probably
want to do it with regular expressions
If you know that it is not broken then indexOf will return you the indedex of the charcter across the whole string where it begins
or -1 if there is no "ereka"
You can do the following to read line-wise
Scanner in = new Scanner(str);
while(in.hasNextLine()) {
String s = in.nextLine();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>and cocatenate all lines into one like that:
There's absolutely no need to do that. Simply the following would suffice:
There's absolutely no need to do that. Simply the following would suffice:
int ixFound = str.replaceAll("\r\n", "").indexOf("eureka");
Yes get request has a limit, and use post for more data.
>>suppose i had data less than 1k and stored in string how do i get to the end of the string.
What do you mean by getting to the end of string ?
Your string will have all the lines that you pasted in your text area.