Python Forum
Help with removing spaces and tabs from a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with removing spaces and tabs from a string
#8
Hello, this is actually a follow-up question on my code. So I actually forgot to put my code inside of a function at the start, so I added it in and its saying that its not giving the same output I had before.

string = input("Enter a string: \n")

 

def trim(string):

    newstring = ""

    pos = 0 

    length = len(string)

    

    while (pos < length

       ): 

       if (string[pos].isspace() != True

        ):

        newstring = newstring + string[

            pos] 

    pos += 1 

 

  

 

print(trim(""))
Reply


Messages In This Thread
RE: Help with removing spaces and tabs from a string - by msqpython - Jan-21-2021, 09:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I use tabs and spaces? (how to resolve error TabError: inconsistent) Onanism 15 6,295 Mar-24-2022, 07:57 PM
Last Post: Gribouillis
  Tab character in a string prints 8 spaces hecresper 6 21,209 Aug-27-2019, 02:38 PM
Last Post: snippsat
  Removing dublicates from a string JoeNancy 6 3,761 May-20-2018, 12:55 PM
Last Post: JoeNancy
  Removing string within string fivestar 2 3,218 Oct-20-2017, 04:30 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020