0

I've scanned the questions here as well as the web and haven't found my answer, this is my first question and I'm a noobie to (wx)Python so go easy on me.


Using TextCtrl I'm trying to remove a single character within a string, this string will always start with the same set of characters but the rest of the string is freely editable by the user.

e.g

self.text=wx.TextCtrl(panel,-1"hello world,, today we're asking a question on stackoverflow, what would you ask?")

poor example but how would I find and remove the 11th(',') character so the sentence is more formatted without affecting the rest of the string?

I've tried standard python indexing but I get an error for that, I can successfully remove chunks of the string from the start outwards of the end inwards but I need only a single character removed.

Again, sorry for the poor terminology, as I said I'm fairly new to python so some of my terms may be a bit iffy.

Ashoka Lella
  • 6,631
  • 1
  • 30
  • 39

1 Answers1

0
self.text.SetValue(self.text.GetValue()[:10] + self.text.GetValue()[11:] ) 

maybe??

self.text.SetValue(self.text.GetValue().replace(",,",",")

maybe?

its not really clear what you are trying to accomplish here ...

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I want to replace a single character within a string without altering(removing,moving, etc) the rest of the string I have tried self.x.SetValue(self.x.GetValue()[]) but all that seems to do is clear the entire string starting from the start/end until the specified number – user3761590 Jun 20 '14 at 22:41
  • you asked about removing ... now its replacing? both examples posted in my answer remove a character from your string value in the `self.text` – Joran Beasley Jun 20 '14 at 23:32
  • strings are not mutable in python you must make a new string, leaving out the parts that you do not want – Joran Beasley Jun 21 '14 at 19:35