Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2003.03.20;
Скачать: [xml.tar.bz2];

Вниз

Variant && Srtring   Найти похожие ветки 

 
San   (2003-03-05 16:50) [0]

Help !!!
Как получить коды символов строки, записанной в переменную V, типа VARIANT ? Или как проитись по символам переменной V ?


 
Palladin   (2003-03-05 16:57) [1]

молча и тупо
var
s:string;

s:=v;


 
San   (2003-03-05 17:29) [2]

Так я и сам умею. Проблема в другом - нужны КОДЫ символов (которые возвращает ORD() ) из переменной V !


 
Mike_Goblin   (2003-03-05 18:35) [3]

Тип Variant может содержать не только строки, но и много чего еще. Поэтому приведи к строке и получай коды из строки, так будет более корректно


 
Palladin   (2003-03-05 18:46) [4]

ну зачем быть таким неумным
после вышеприведенной операции
ord(s[1]) или сколько там тебе надо...

variant это не тот тип что бы кнему так просто обращатся...


 
Набережных С.   (2003-03-05 20:44) [5]

var
V: Variant;
n:integer;
S: string;
begin
V:="Hello";
if VarIsStr(V) and not VarIsType(V, varOleStr) then
begin
for n:=1 to Length(String(TVarData(V).VString)) do
s:=s+IntToStr(Ord(String(TVarData(V).VString)[n]))+" ";
end;
ShowMessage(s);
end;


 
Романов Р.В.   (2003-03-05 20:54) [6]

V := 500;
for i := 1 to Length(String(V)) do
ShowMessage(String(V)[i]);


 
Набережных С.   (2003-03-05 22:00) [7]

>Романов Р.В. © (05.03.03 20:54)

Это скомпилится примерно в такой код:

s: string;
n:integer;

n:=TVarData(V).vInteger;
s:=IntToStr(n);
for i:=1 to Length(s) do
ShowMessage(S[i]);

Т.е. то же самое, что предложил Palladin © (05.03.03 16:57)


 
Романов Р.В.   (2003-03-05 22:03) [8]


> Набережных С. (05.03.03 22:00)

Согласен


 
San   (2003-03-06 10:30) [9]

Прблема в том, что строка эта из EXCELa , и при переводе варианта в строку коды символов меняются. Не знаю почему...


 
Набережных С.   (2003-03-06 20:46) [10]

из EXCELa ты получаешь WideString. Выполни с ней это:
if
(TVarData(V).VType = varString)or
(TVarData(V).VType = varOleStr)
then
begin
for n:=1 to Length(String(TVarData(V).VString)) do
s:=s+IntToStr(Ord(String(TVarData(V).VString)[n]))+" ";
ShowMessage(s);
end;

А потом это:
if TVarData(V).VType = varOleStr then
begin
for n:=1 to Length(WideString(TVarData(V).VString)) do
s:=s+IntToStr(Ord(WideString(TVarData(V).VString)[n]))+" ";
ShowMessage(s);
end;



 
San   (2003-03-10 16:26) [11]

>> Набережных С.
Спасибо, помог !
Остался у меня один вопрос. Может он и глупый, но всё же.
При проходе по строке, каждый символ раскладывается на 2 составляющие: код символа и ещё какое-то число. Поясни пожалуйста, что это за число ?


 
Palladin   (2003-03-10 16:39) [12]

выдержка из хелпа

One approach to working with ideographic character sets is to convert all characters to a wide character encoding scheme such as Unicode. Unicode characters and strings are also called wide characters and wide character strings. In the Unicode character set, each character is represented by two bytes. Thus a Unicode string is a sequence not of individual bytes but of two-byte words.
The first 256 Unicode characters map to the ANSI character set. The Windows operating system supports Unicode (UCS-2). The Linux operating system supports UCS-4, a superset of UCS-2. Delphi/Kylix supports UCS-2 on both platforms. Because wide characters are two bytes instead of one, the character set can represent many more different characters.

Using a wide character encoding scheme has the advantage that you can make many of the usual assumptions about strings that do not work for MBCS systems. There is a direct relationship between the number of bytes in the string and the number of characters in the string. You do not need to worry about cutting characters in half or mistaking the second half of a character for the start of a different character.
The biggest disadvantage of working with wide characters is that Windows 9x only supports a few wide character API function calls. Because of this, the VCL components represent all string values as single byte or MBCS strings. Translating between the wide character system and the MBCS system every time you set a string property or read its value would require additional code and slow your application down. However, you may want to translate into wide characters for some special string processing algorithms that need to take advantage of the 1:1 mapping between characters and WideChars.


 
Набережных С.   (2003-03-10 18:23) [13]

Сходи сюда, если интересно
http://www.unicode.org



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2003.03.20;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.008 c
14-64351
Ник
2003-03-05 09:20
2003.03.20
Давно не обновлялся раздел Новости VCL!


14-64346
user_000
2003-03-05 09:46
2003.03.20
как работать с RARом???


1-64177
Andy BitOff
2003-03-07 21:01
2003.03.20
Передача параметра


3-63969
FREEMAN
2003-02-27 00:36
2003.03.20
Вопрос по работе с БД


7-64396
maxfiles
2003-01-22 01:19
2003.03.20
Как отловить мультимедийные клавиши на клаве?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский