Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links


Retrieve attribute as string

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 27-02-2010
Member
 
Join Date: Dec 2009
Posts: 202
Retrieve attribute as string

Sponsored Links
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.

Reply With Quote
  #2  
Old 27-02-2010
Member
 
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.
Reply With Quote
  #3  
Old 27-02-2010
Member
 
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.
Reply With Quote
  #4  
Old 27-02-2010
Member
 
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.
Reply With Quote
  #5  
Old 27-02-2010
Member
 
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.
Reply With Quote
  #6  
Old 27-02-2010
Member
 
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);}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Retrieve attribute as string"
Thread Thread Starter Forum Replies Last Post
How to set file attribute? Julli_gaada Tips & Tweaks 3 21-11-2009 07:05 PM
How to retrieve a substring in a string? Protector Software Development 3 15-10-2009 07:20 PM
How to Manipulate String using PHP String Functions ComPaCt Software Development 3 21-09-2009 09:07 AM
How to set HTML Tag Attribute in asp.net Shashee Software Development 3 08-06-2009 10:39 PM
Custom AD attribute - [WP] OmJaa Active Directory 3 11-03-2008 07:17 PM


All times are GMT +5.5. The time now is 02:06 AM.