Форум » [x]Harbour » [ ] (string) Harbour » Ответить

[ ] (string) Harbour

Dima: Смотрю в Xharbour есть такая фича а в Harbour похоже ни кто не перенес. [pre2] [ ] (string) : Character operator (unary): retrieves a character from a string. Syntax <cString>[<nPos>] Arguments <cString> <cString> is a character string containing at least one character. <nPos> <nPos> is a numeric expression which indicates the ordinal position of the character to retrieve. Description The character retrieves a single character at position <nPos> from the string <cString>. The value for <nPos> mus be in the range of 1 to Len(<cString>). Note: if <nPos> is a negative value, the operator retrieves the character Abs(<nPos>) from the end of the the string. Examples // The example shows how to access and change characters in a string. // Two functiosn are programmed which convert a numeric value to/from // a string containing only "1" and "0". PROCEDURE Main LOCAL cStr cStr := "xHarbour" ? cStr[5] // result: b cStr[5] := "B" ? cStr // result: xHarBour cStr[-1] := "B" ? cStr // result: xHarBouB RETURN [/pre2] В этой связи вопрос. Есть строка вида Cstr:="11111000001001101010101" Нужно вытащить ну скажем 12 символ. На ум приходит только такой вариант substr(Cstr,12,1). Какие есть еще варианты ?

Ответов - 2

AlexMyr: Dima пишет: Смотрю в Xharbour есть такая фича а в Harbour похоже ни кто не перенес. смотрим core\contrib\hbxpp\tests\opover.prg правда этот момент с индексом -1 где-то уже обсуждали Dima пишет: cStr[-1] := "B"

Dima: AlexMyr пишет: смотрим core\contrib\hbxpp\tests\opover.prg Сенкс



полная версия страницы