Using substring to edit individual characters

Asked by Nomis Carr

Hey there (using Sikuli r930 and Windows Vista 32 bit.)

Sorry if this is woefully basic but i have been unable to find any information on using substring (or the equivalent function)

I am trying to edit the following string;

dateMeeting = input("Please Enter the Date of the Meeting:","dd/mm/yyyy")

#if a date like 03/10/1990 is entered, i want to edit the dateMeeting variable so that it no longer starts with "0"

if dateMeeting.substring(0) == 0:
      myDate = dateMeeting.substring(1,10)
      print myDate
else:
    print dateMeeting

essentially need help with editing specific character positions within a string.

Many thanks

Australia

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
obiwan-92
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
obiwan-92 (obiwan-92) said :
#1

Hello.

Try this :
if dateMeeting.startswith('0'): myDate = dateMeeting[1:]
print myDate

It should be work.

Happy new year !!
Regards.

Revision history for this message
Nomis Carr (s-carr) said :
#2

Many thanks. That worked perfectly.
Recognising that everyone is hung over as balls today, i was hoping it might be possible to learn a bit more about manipulating strings.

I haven't been able to find anything about using 'startswith';
What if i want to change the second character?

Are there user friendly lists of these functions?
Where should i go to learn more about this type of coding and Sikuli in general.

Many thanks

A hung over Aussie.

Revision history for this message
Nomis Carr (s-carr) said :
#3

Thanks obiwan-92, that solved my question.

Revision history for this message
Nomis Carr (s-carr) said :
#4

Still need help with strings in general.

Revision history for this message
obiwan-92 (obiwan-92) said :
#5

Hello.

Well, if you want to check and change only the second character :
if dateMeeting[1]=='0': myDate = dateMeeting[0] + dateMeeting[2:]

This type of coding is named Jython. It's just the Python script with some Java library.
Here, we have used only the Python features.

http://docs.python.org/2/library/string.html -> The original Python documentation, you will find your function at the end.
http://www.jython.org/docs/library/string.html -> The real Jython documentation.

The documentation of Sikuli is here : http://doc.sikuli.org/

Regards.

Revision history for this message
Best obiwan-92 (obiwan-92) said :
#6

Correction.
For python the documentation is here : http://docs.python.org/2/library/stdtypes.html

Revision history for this message
Nomis Carr (s-carr) said :
#7

Thanks obiwan-92, that solved my question.