Results 1 to 6 of 6

Thread: Retrieve attribute as string

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Retrieve attribute as string

    Hello,
    I want to retrieve the name of an attribute in a string
    Example:
    Code:
    int size = 3;
    String str = "Size";
    How can this be done in java, I am new to this programming language, so please I need your help. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Retrieve attribute as string

    Hello,
    I think you can make a code similar to this
    Here is the general form of the code
    Code:
    Field e = ...
    ...
    e.getClass().getCanonicalName();
    More than how you'll find your Field, I mean to say why do you want such an output or result that will be unnecessary for a program.

  3. #3
    Join Date
    Nov 2008
    Posts
    240

    Re: Retrieve attribute as string

    Hello,
    Even I was trying a similar kind of a program, I used you solution and thanks I found what I wanted. If you do not mind one more question.
    I want to retrieve the name of the instance of a class (the object name what).
    Code:
    public class mcls (
    ...
    display the instance name
    ...
    }
    
    public static void main (String [] args) (
    inst mcls = new mcls ();
    }
    Any help on this will be highly appreciated.

  4. #4
    Join Date
    Nov 2009
    Posts
    330

    Re: string as an attribute

    Hello,
    If it's just to test and see who called your Standings, you can do:
    Code:
    Exception ex = new Exception();
    ex.printStackTrace();
    I think it would be better to use the stack trace in your code. Otherwise I am not sure how to do. If you need any more information on this then please visit the Sun's official site and there you can find methods or function or classes for all the java programming language.

  5. #5
    Join Date
    Nov 2009
    Posts
    356

    Re: Retrieve attribute as string

    Hello,
    Basically recover "inst" has no meaning in the sense there in the code. The variable name is the name of the instance pointer, so the body can not know the variables that reference. And if you approach it in your body that you do for a variable. Is that clear enough? If you are not understanding this then I am sorry you have to read some basics of java first and then try to implement the code or try coding.

  6. #6
    Join Date
    Dec 2009
    Posts
    178

    Re: Retrieve attribute as string

    Hello,
    I am new to java and I do not exactly know what you need, but I have a sample code with me, see if this helps you.
    Here is the code
    Code:
    String str="some text";
    String vldch="some ";
    str=str.toLowerCase(); // case desense!
    for (int i=0;i<str.length();i++)
    {
      char c=str.charAt(i);
      if (vldch.indexOf(c)==-1)
         {System.out.printf(" character["+c+"] at position "+i);}
    }

Similar Threads

  1. How to set file attribute?
    By Julli_gaada in forum Tips & Tweaks
    Replies: 3
    Last Post: 21-11-2009, 08:05 PM
  2. How to retrieve a substring in a string?
    By Protector in forum Software Development
    Replies: 3
    Last Post: 15-10-2009, 07:20 PM
  3. How to Manipulate String using PHP String Functions
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 21-09-2009, 09:07 AM
  4. How to set HTML Tag Attribute in asp.net
    By Shashee in forum Software Development
    Replies: 3
    Last Post: 08-06-2009, 10:39 PM
  5. Custom AD attribute - [WP]
    By OmJaa in forum Active Directory
    Replies: 3
    Last Post: 11-03-2008, 07:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,658,775.53208 seconds with 16 queries