Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Java prob

Thread view: 
sne - 20 Apr 2006 11:26 GMT
Hey guys,

Please help me with this problem asap.When an adress is entered in a
textfiled in a texbox after pressing enter,it gets stored in the
database with the newline character which shows a small box.How do i
remove this new line from the adress in java.

Thanks
Reply soon
Snehal
Gregor Kovač - 20 Apr 2006 11:45 GMT
> Hey guys,
>
[quoted text clipped - 6 lines]
> Reply soon
> Snehal
If the new line is at the end you could use:
String text = textField.getText();
text = text.substring(0, text.length() - 1);
// now store it in database

Best regards,
       Kovi
Signature

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

| Gregor Kovac | Gregor.Kovac@mikropis.si    |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
|            Experience Linux.               |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Philipp Leitner - 20 Apr 2006 11:52 GMT
you may want to look at the method

String.replaceAll(String regex, String replacement)

If you have the String from the textbox in the variable "tb" you could do

tb=tb.replaceAll("\n","");

i.e. "replace all newlines by "" "

If that does not work it may be that your newline characters are
actually not \n characters, but something else. In that case you have to
replace \n for the actual newline character.

/philipp

P.S.: just a sidenote for further posts: usually people react quite
annoyed on sentences like "(...) help me with this problem asap (...)".
I would avoid that _especially_ if I am in a hurry :-)

sne schrieb:
> Hey guys,
>
[quoted text clipped - 6 lines]
> Reply soon
> Snehal
Bjorn Abelli - 20 Apr 2006 12:17 GMT
"sne" wrote...

> When an adress is entered in a
> textfiled in a texbox after pressing enter,
> it gets stored in the database with the newline
> character which shows a small box. How do i
> remove this new line from the adress in java.

One option is to use

 .trim();

...on the String before storing it to the database, which not only removes
the newline character from the end, but removes all leading and trailing
whitespaces.

// Bjorn A
sne - 20 Apr 2006 12:35 GMT
Hey guys,

I hv alredy tried replacing any occurence of \n or ascii codes 13 or
10.bt it doesnt work.the data is retrieved from the oracle database
with a small box. Nd i cnt replace the occurence of this character as i
dnt kno wt 2 represent it by.tirm() removes whitespaces bt i wna remove
the new line. i cnt modify the text befre it enters the database as it
is on the frontend.

> "sne" wrote...
>
[quoted text clipped - 15 lines]
>
> Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Philipp Leitner - 20 Apr 2006 12:40 GMT
I remember having a similar problem just recently... for some strange
reasons I could not use replaceAll() on a String produced from an Xerces
Document . I ended up converting the String to char[] and running
through the array, removing \n by hand. Perhaps you have a similar issue
here (but I guess the more probable reason is that the newline isn't a
\n, but something else?)

/philipp

sne schrieb:
> Hey guys,
>
[quoted text clipped - 23 lines]
>>
>> Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
sne - 20 Apr 2006 12:51 GMT
Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
doesnt work on jdk1.3 so cnt use tat
Gordon Beaton - 20 Apr 2006 12:56 GMT
> Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
> doesnt work on jdk1.3 so cnt use tat

J xb dnt f the other wq i, dvs ej uW!

HTH!

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Andrew McDonagh - 20 Apr 2006 13:00 GMT
>> Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
>> doesnt work on jdk1.3 so cnt use tat
[quoted text clipped - 4 lines]
>
> /gordon

v fun e, u bt me 2 it
Philipp Leitner - 20 Apr 2006 12:58 GMT
you /can/ run through the whole string "by hand" like that

char[] chars = yourString.toCharArray();
char[] newchars = new char[chars.length];
for(int i=0; i< chars.length; i++)
    if(chars[i]!='\n')
        newchars[i]=chars[i];
String yourNewString = new String(newchars);

The code above is untested, but should generally work.

/philipp

P.S.: I guess though that there may be a lot better ways to do it, also
in 1.3, but I have no clue what methods are available there, and which
aren't.

sne schrieb:
> Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
> doesnt work on jdk1.3 so cnt use tat
Andrew McDonagh - 20 Apr 2006 12:59 GMT
> Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
> doesnt work on jdk1.3 so cnt use tat

(I wonder how long it'll be before Spelling Police start moaning)

I 1der ow lng b4 Spelin Polce strt moang
Chris Uppal - 20 Apr 2006 13:28 GMT
> Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
> doesnt work on jdk1.3 so cnt use tat

No way am I even going to /try/ to read that !

   -- chris
Roedy Green - 20 Apr 2006 15:23 GMT
>Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
>doesnt work on jdk1.3 so cnt use tat

GLOBABLLY OPTIMISE!  That saved you 1 second in typing, and added 10
seconds to the read time each of the 100 odd people who read your
post.

Textspeak only makes sense when you have a single reader, and a very
awkward keyboard.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Monique Y. Mudama - 20 Apr 2006 17:21 GMT
> Ya the newline is nt \n tats fr sure. so wt cn b done. nd replaceall
> doesnt work on jdk1.3 so cnt use tat

Can I buy a vowel?  (And some consonants and some excedrin?)

Signature

monique

Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 20 Apr 2006 22:05 GMT
On Thu, 20 Apr 2006 10:21:32 -0600, "Monique Y. Mudama"
<spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
said :

>Can I buy a vowel?

LOL.  Brv!
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Gordon Beaton - 20 Apr 2006 12:43 GMT
> I hv alredy tried replacing any occurence of \n or ascii codes 13 or
> 10.bt it doesnt work.the data is retrieved from the oracle database
> with a small box. Nd i cnt replace the occurence of this character
> as i dnt kno wt 2 represent it by.tirm() removes whitespaces bt i
> wna remove the new line. i cnt modify the text befre it enters the
> database as it is on the frontend.

Perhaps the problem is due to a simple misunderstanding of what
exactly trim() does...

Most importantly, trim() does *not* change the string you call it on,
it *returns* a trimmed copy of the original. Remember, Strings are
immutable.

So this will not work:

 String s = getString();
 s.trim();               // leaves s unchanged
 database.addString(s);

but this will:

 String s = getString();
 String t = s.trim();
 database.addString(t);

and this:

 String s = getString();
 database.addString(s.trim());

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

sne - 20 Apr 2006 12:58 GMT
I cnt change the data befre it enters the databsae.i hv 2 remove the
newline from the data retrieved from the database
Gordon Beaton - 20 Apr 2006 13:10 GMT
> I cnt change the data befre it enters the databsae.i hv 2 remove the
> newline from the data retrieved from the database

You *could* try to understand the point I was trying to make about
trim() and come to your own conclusions.

 String s = database.get();
 return s.trim();

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Bjorn Abelli - 20 Apr 2006 13:23 GMT
"Gordon Beaton" wrote...
>> I hv alredy tried replacing any occurence of \n or ascii codes 13 or
>> 10.bt it doesnt work.the data is retrieved from the oracle database
[quoted text clipped - 9 lines]
> it on, it *returns* a trimmed copy of the original. Remember,
> Strings are immutable.

And the same goes for

 s = s.replace('\r').replace('\n')

If still neither trim or replace works, you should try to "debug the
string", in order to see what character it really is, e.g.:

  int c = s.charAt(s.length()-1);
  System.out.println(c);

// Bjorn A
Roedy Green - 20 Apr 2006 15:19 GMT
>Please help me with this problem asap.When an adress is entered in a
>textfiled in a texbox after pressing enter,it gets stored in the
>database with the newline character which shows a small box.How do i
>remove this new line from the adress in java.

String.trim
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.