網頁

2017年10月16日 星期一

String index V.S. Array index in Delphi

I'm used to develop code in C, however someday I meet the need which the code was written in Delphi.

The amazing fact in Delphi is the index on array and string differs ! This is really shock, it shocked me almost put hands in my mouth. 嚇得我吃手手...

In Delphi, Strings are 1-indexed, but arrays are 0-indexed.

也就是說如果有一個變數被設為 String 例如說 S:=Foo.Bar().AsString;
如果要存取 S 的第一個字元要使用 S[1] 才會是正確的字元。

If S is assigned as a string variable, the first character would be S[1] not S[0];

沒有留言:

張貼留言

Python TypeError: 'module' object is not callable

程式碼其實相當簡單 import random random.random() 那問題出在哪?出在當初的檔名取名為 random.py 結果造成 Python 在 import 的時候造成問題。所以在取名Python 的檔名時,切記不要取成跟 Default Module...