I asked a question and a user posted a comment of the form 'did you try ...'. This did indeed work and I consider the question answered. I wrote another comment on my question confirming that this works and thanked the poster. Questions: How should I mark the question as answered? How do I give credit to the commenter for solving my problem? Thanks.
As @MartinSleziak explained in a comment, the best way to proceed in this case is to post your solution as an answer.
In general one can guess that a commenter chooses to comment rather than post a full answer for a reason, hence such comments are in effect a carte blanche to the OP to post their own answer. -- Did
Comments of the form "Have you tried..." are often an attempt to clarify the Question, and may not always be so much an invitation for the OP to answer their own question as a diagnostic toward pinning down the lacuna.
If a Question can be answered by the OP based on such Comment, I'd personally be happy to have them post an Answer, but if I received such a Comment I'd be inclined to respond with an invitation to that being expanded into an Answer so I could Accept it.