2020年10月12日 星期一

程式設計的一些小技巧

 

1. Check key in a dictionary

PHP : "key" in obj

Python : if "key1" in d:

Java : hashMap.containsKey("bb")

2. Split string

PHP : list($encrypted_data, $iv, $ivh) = explode('::', base64_decode($garble), 2);

Python : metas = resp.content.split('/')

Java : String[] tokens = str.split(":");

3. Check variable is null/undefined

JS : if( var === undefined )


沒有留言: