My Notes


Fishing, Golfing and Programming

Python to Typescript, String functions

Posted by Ahchi on Sep 18, 2017

Recently, I have tried to rewrite a Python web scraping program with Typescript and Electron, I have found that both Python and Typescript's String functions have some similarity:

 

Python Typescript
str.find('-') str.indexOf('-')
str.rfind('-') str.lastIndexOf('-')
str.strip() str.trim()
str.upper('a') str.toUpperCase('a')
str.lower('A') str.toLowerCase('A')
str[p1 : p2] str.substring(p1, p2)
str.split(',') str.split(',')
str.zfill(2) str.padStart(2, '0')
'a' in str str.includes('a')
str.replace('a', 'b') str.replace(/a/g, 'b')