Tuesday, September 20, 2022

[FIXED] How to convert Attributes to String?

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)

No comments:

Post a Comment

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