DEV Community

Himanshupal0001
Himanshupal0001

Posted on

#1 How to find a particular character in string?? (*The thought process)

Image description

The above code snippet might be total utter for the beginners.

I myself struggled a lot while learning code(still struggling '-'). But I've improved myself over the ears(my eyesight was in negative though ngl)... sorry years by copying same code again and again.

Just kidding ...but most of us do right? Copying same thing again and again but still struggling. SO why is that?

What I've learning is that copying code is not bad but not putting thoughts in it is bad.

As you can see the code below

Image description

I'm gonna explain my thought process here.

  1. As we are seeing in first line there's a variable str storing string in it.

  2. I want to extract only fullstops (.)(.)...hehe (note* 2 fullstops for plural) . Yea so we only want fullstops from the string.

  3. So what can I do?

  4. First I want to know the ascii code of each character.

  5. So I googled it.

  6. I got the results.

  7. Then I just compare the ascii code to integer value. If matched then print it to console. Oh..... you can use trim function to trim the space.

At the end I just wanna say focus on finding the solution rather then code. You can always google the code for it if you have the solution. Break it in steps. Do things step by step. It will help you in long run. Google code not solution!!!!

Top comments (0)