The Artima Developer Community
Sponsored Link

Java Answers Forum
Setting the encoding for a char to a specified string

2 replies on 1 page. Most recent reply: Oct 1, 2003 2:50 PM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Rowena S

Posts: 1
Nickname: rowena
Registered: Oct, 2003

Setting the encoding for a char to a specified string Posted: Oct 1, 2003 2:57 AM
Reply to this message Reply
Advertisement
Hi, I'm new to Java, and I was wondering how to set an encoding for a char to a specified string. This is what I have been trying but it doesn't compile and says I need extra brackets, I'm not sure where.
   public void setCode(char ch, String string) {
  if(ch.equals ('0'))
   string.valueOf(ch) = string;
   if(string.valueOf(ch).equals '0')
    String str = String.valueOf(str.charAt(i));
     this.ch = ch;
     }


Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Setting the encoding for a char to a specified string Posted: Oct 1, 2003 2:47 PM
Reply to this message Reply
A couple of things:
The equals method in line 4 doesn't have an opening parenthesis.
That's ok, though, because java.lang.String doesn't have an equals method that takes a char.

In line 5, you are declaring and initializing str as the lvalue, but you are attempting to reference it in the rvalue expression; it is not yet in scope within the rvalue expression. (and would cause a NullPointerException if it were)

Can you explain a little more what you're trying to do?

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Setting the encoding for a char to a specified string Posted: Oct 1, 2003 2:50 PM
Reply to this message Reply
Also, line 2 should be
if (ch == '0') // unlike c#, java char variables do not have methods

Flat View: This topic has 2 replies on 1 page
Topic: how will i get total no of rows in the table.. Previous Topic   Next Topic Topic: Help Please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use