2011年4月18日 星期一

regular expression: describes a pattern of characters

JavaScript需要將特定字元篩選出來,然後移除掉。
這時候就需要RegExp啦!!

我是高中生,我要怎樣自己賺錢買相機、機車?

Moblile01上熱烈討論這兩個小朋友的差別
一個說要說服家長幫他出錢買相機,讓他可以學攝影。
大多人給予很多意見,雖然開砲的還是有~
另一個在抱怨爸媽沒有幫他買機車,這樣他以後會很糗...
網友開砲開的可過癮的...XD

2011年3月25日 星期五

Handle IP address convert to int or char(dot IP)

This code will do
1. convert char IP address to four int
2. convert four int var to one int
3. convert four int var to one char
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include 
int main() {
 char arr[] = "192.168.1.102\0 "; //extended to be able to fit up to maximum length
 unsigned short a, b, c, d;
 sscanf(arr, "%hu.%hu.%hu.%hu", &a, &b, &c, &d );
 arr[0] = '\0'; // cleared to make sure it's not just the same string coming back
 unsigned long ipAddr = ( a << 24 ) | ( b << 16 ) | ( c << 8 ) | d;
 a = (ipAddr & (0xff << 24)) >> 24;
 b = (ipAddr & (0xff << 16)) >> 16;
 c = (ipAddr & (0xff << 8)) >> 8;
 d = ipAddr & 0xff;
 sprintf(arr, "%hu.%hu.%hu.%hu", a, b, c, d);
 puts(arr);
}


Or, these is a api to do it

1
2
3
4
5
6
7
8
9
10
11
int main()
{ char ip[] = "192.168.1.102"; long long_address = inet_addr (ip) ; struct in_addr addr; addr.s_addr = long_address; char *dot_ip = inet_ntoa(addr); printf("%s",dot_ip); }


===========================================
reference from:
http://www.cplusplus.com/forum/general/9403/
http://stackoverflow.com/questions/1505676/how-to-convert-ip-address-from-char-to-int
http://beej.us/guide/bgnet/output/html/multipage/inet_ntopman.html  (good)
http://beej.us/guide/bgnet/output/html/multipage/inet_ntoaman.html
http://www.aboutmyip.com/AboutMyXApp/IP2Integer.jsp
===========================================


後記:
後來發現一篇文章最有用

從 inet_ntoa 看 thread safe 的 API


inet_ntoa會有thread safe的問題,最好直接改用inet_ntop

2011年3月4日 星期五

在WORD中Backspace鍵失效

微軟常常會讓人有無限的驚喜...
前幾天忽然發現,在word和outlook中。反白一段文字,卻無法用backspace(←)刪除。
然而在其他的軟體,甚至是其他的office軟體裡,卻都沒有這個問題。
這困擾了我幾天...
還一度懷疑,是不是本來就沒有這個功能,是我自己憑空想出來的 Orz