PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 20, 2022

[FIXED] How to convert Attributes to String?

 September 20, 2022     hashmap, java, ldap, openldap     No comments   

Issue

I want to convert Attributes to String so that I can trim and get a substring of the attribute value.

Here is my code:

Attribute attrs = match.getAttributes();

NamingEnumeration e = attrs.getAll();
System.out.println(attrs.get("cn"));
System.out.print(attrs.get("uniqueMember"));

unique_members[i] = attrs.get("uniqueMember");

I am facing an error in the last line where I want to store the value of uniqueMember to the unique_members array. Error:

Type mismatch: cannot convert from Attribute to String

I have tried the following so far:

unique_members[i] = (String)attrs.get("uniqueMember");

It doesn't solve the issue and I am getting error:

Cannot cast attribute to String.


Solution

Use unique_members[i] = attrs.get("uniqueMember").toString() to convert the attribute value to a string.

For more informationens see the javadoc of BasicAttribute or javax.naming.directory.Attribute



Answered By - Jens
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing