-2

I am pulling user information from my server's database. When the user is found in the database, an object is returned to me and when I NSLog the object it looks like this:

(
    "<PFUser:981038hajsh98:(null)> {\n    \"Phone_Number\" = 5859921091;\n    email = \"usersemail@aol.com\";\n    username = jeff849;\n    verificationCode = 3240;\n}"
)

I need a way to extract just the "username" value. So with the above example, I would need to extract this exactly: jeff849

How can I do this?

Edit: The object that I need to extract a specific substring out of is an NSString object.

user3344977
  • 3,584
  • 4
  • 32
  • 88

1 Answers1

2

That isn't a string, it's a PFUser object from the Parse API class. When you log an object, the description method is called, which is what you are seeing above. Given that it's a user object, use the username property to get the value.

NSLog(@"%@", pfuser.username);

That's assuming the variable that your PFUser object is pfuser. You're obviously logging that object somehow to get that string.

Update

Looking at the log it might be an NSArray of PFUser's. In that case

for (PFUser *user in databaseUsers) {
    NSLog(@"%@", user.username);
}
Jason Harwig
  • 43,743
  • 5
  • 43
  • 44
  • Jason, yes I am using Parse. It is scanning the parse database for a phone number, and then if it finds that phone number, it returns the entire row for that user. That is why the object prints to the console with a username, email, verification code, etc. Any idea how I can just grab the username text? – user3344977 Feb 24 '14 at 20:19
  • Use the username property as shown above (according the the API docs) I haven't used Parse. – Jason Harwig Feb 24 '14 at 20:41