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

Вниз

Есть ли в Дельфи фунции чтобы преобразовать строку   Найти похожие ветки 

 
Сергей01   (2002-09-17 05:51) [0]

в массив a[1]="1"; a[2]="2"; a[3]="tri"; a[4]="text"; ? В перле и php есть и это очень удобно. Также есть функции чтобы собирать массив в одну строку. В Дельфи не нашёл. Подскажите пожалуйста, или может у кого есть текст таких функций ?


--------------
Есть ли в Дельфи фунции чтобы преобразовать строку "1,2,tri,text" в массив a[1]="1"; a[2]="2"; a[3]="tri"; a[4]="text"; ? В перле и php есть и это очень удобно. Также есть функции чтобы собирать массив в одну строку. В Дельфи не нашёл. Подскажите пожалуйста, или может у кого есть текст таких функций ?


 
gek   (2002-09-17 07:01) [1]

Нет


 
Hooch   (2002-09-17 07:05) [2]

RxLib, модуль RxStrUtils функции ExtractWord, WordCount и т.д.


 
Alx2   (2002-09-17 07:18) [3]


procedure TForm1.Button8Click(Sender: TObject);
Var
Result : String;
k : integer;
begin
with TStringList.Create do
try
CommaText :="1,2,tri,text";
for k := 0 to Count-1 do Strings[k] := Format("a[%d]:="%s"",[k+1,Strings[k]]);
ShowMessage(Text);
finally
Free;
end;
end;


 
Song   (2002-09-17 09:03) [4]


With TStringList.Create Do
try
Text:="1,2,tri,text";
Text:=StringReplace(Text,",",#13#10,[rfReplaceAll]);
For t:=0 to Count-1 Do a[t]:=Strings[t];
finally
Free;
end;


 
Alx2   (2002-09-17 09:11) [5]

>Song © (17.09.02 09:03)
А я, кажись, загнался :)


 
ЮЮ   (2002-09-17 09:20) [6]

>Alx2 © (17.09.02 09:11)
>А я, кажись, загнался :)

По моему, не очень :-). Ведь достаточно StringList.CommaText:="1,2,tri,text";

>Song © (17.09.02 09:03)
>автору
И использовать не некий a[i], а StringList.Strings[i]


 
Song   (2002-09-17 09:22) [7]

2Alx2 © (17.09.02 09:11)
Да нет, на загнался. Просто я предложил ещё один способ.

2ЮЮ © (17.09.02 09:20)
По условию задачи нужно было получить массив a[]. Что я и сделал :-))


 
Alx2   (2002-09-17 09:27) [8]

>По условию задачи нужно было получить массив a[].
>Что я и сделал :-))
А я невнимательно пялился на вопрос и понял, что нужно получить строки типа как в Alx2 © (17.09.02 07:18)





 
MetalFan   (2002-09-17 10:28) [9]

procedure CommaSeperatedToStringList(AList: TStrings; const Value: string);

Parameters

AList: TStrings

List to store the values.


const Value: string

String containing comma-delimited values.


Description

CommaSeperatedToStringList is a procedure used to fill the TStringList AList parameter with the values from the Value parameter.
AList is cleared prior to adding values in the procedure.
Value is a comma-delimited list of values to loaded in the TStringList. Value can contain items that include the comma separator by using double quotation marks to enclosed the item. For example:

"Item One, "Item Two, with comma", Item Three"


 
MetalFan   (2002-09-17 10:45) [10]

function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;

Description

Use ExtractStrings to fill a string list with the substrings of the null-terminated string specified by Content.

Separators is a set of characters that are used as delimiters, separating the substrings. Carriage returns, newline characters, and quote characters (single or double) are always treated as separators. Separators are ignored when inside a quoted string until the final end quote. (Note that quoted characters can appear in a quoted string if the quote character is doubled.)

WhiteSpace is a set of characters to be ignored when parsing Content if they occur at the beginning of a string.

Content is the null-terminated string to parse into substrings.

Strings is a string list to which all substrings parsed from Content are added. The string list is not cleared by ExtractStrings, so any strings already in the string list are preserved.

ExtractStrings returns the number of strings added to the Strings parameter.

Note: ExtractStrings does not add empty strings to the list.


 
MetalFan   (2002-09-17 10:45) [11]

function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;

Description

Use ExtractStrings to fill a string list with the substrings of the null-terminated string specified by Content.

Separators is a set of characters that are used as delimiters, separating the substrings. Carriage returns, newline characters, and quote characters (single or double) are always treated as separators. Separators are ignored when inside a quoted string until the final end quote. (Note that quoted characters can appear in a quoted string if the quote character is doubled.)

WhiteSpace is a set of characters to be ignored when parsing Content if they occur at the beginning of a string.

Content is the null-terminated string to parse into substrings.

Strings is a string list to which all substrings parsed from Content are added. The string list is not cleared by ExtractStrings, so any strings already in the string list are preserved.

ExtractStrings returns the number of strings added to the Strings parameter.

Note: ExtractStrings does not add empty strings to the list.


 
NeyroSpace   (2002-09-17 10:48) [12]

2 Сергей01
Вам прийдется написать свою ф-цию.
Перед этим обязательно посмотрите исходники Делфи ф-ций работы со строками.


 
Zemal   (2002-09-17 11:55) [13]

Могу подсказать только одно: есть класс TStringList (потомок TStrings), у этого класса есть масса полезных свойств для работы с массивами строк. И нечего гонки тут устраивать!!! Каждый гонит, а чего и сам не знает!!! Вот пример:

var
StrLst : TStringList;
S : String;
begin
StrLst := TStringList.Create;
... // заполнение массива строк значениями
S := StrLst.CommaText; // разделитель ";"
StrLst.Delimiter := #9;
S := StrLst.DelimitedText; // разделитель "Tab"
StrLst.Delimiter := #13;
S := StrLst.DelimitedText; // разделитель "Enter" (перенос строки)
StrLst.Clear;
StrLst.Free;
end;

Вот и все ваши проблемы. Только чего орать и разоряться, если не знаешь?!?!?! Я считаю так: незнаешь - промолчи!


 
Alx2   (2002-09-17 12:21) [14]

>Zemal © (17.09.02 11:55)
>Только чего орать и разоряться, если не знаешь?!?!?! Я считаю >так: незнаешь - промолчи!

Извини, пожалуйста. Я обязательно научусь разбивать строки (или как это правильно называется?). Просто мне хотелось немножко порисоватся и совсем забыл, что на форуме надо быть вежливым и не кичиться тем, чего не знаешь (да и чем знаешь - тоже) и вообще не принято рисоваться. Еще раз приношу свои извинения всем, кому намозолил глаза своими выскакиваниями....


 
Alexeus   (2002-09-17 15:10) [15]

cut from Delphi help:

The following example uses a variant open array parameter in a function that creates a string representation of each element passed to it and concatenates the results into a single string. The string-handling routines called in this function are defined in SysUtils.

function MakeStr(const Args: array of const): string;

const
BoolChars: array[Boolean] of Char = ("F", "T");
var
I: Integer;
begin
Result := "";
for I := 0 to High(Args) do
with Args[I] do
case VType of
vtInteger: Result := Result + IntToStr(VInteger);
vtBoolean: Result := Result + BoolChars[VBoolean];
vtChar: Result := Result + VChar;
vtExtended: Result := Result + FloatToStr(VExtended^);

vtString: Result := Result + VString^;
vtPChar: Result := Result + VPChar;
vtObject: Result := Result + VObject.ClassName;
vtClass: Result := Result + VClass.ClassName;
vtAnsiString: Result := Result + string(VAnsiString);
vtCurrency: Result := Result + CurrToStr(VCurrency^);
vtVariant: Result := Result + string(VVariant^);
vtInt64: Result := Result + IntToStr(VInt64^);

end;
end;

We can call this function using an open array constructor (see Open array constructors). For example,

MakeStr(["test", 100, " ", True, 3.14159, TForm])

returns the string “test100 T3.14159TForm”.



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

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

Наверх




Память: 0.49 MB
Время: 0.009 c
3-97942
wed
2002-09-08 16:58
2002.09.30
Формат (округление) в SQL


3-97975
vlad40
2002-09-09 12:25
2002.09.30
Ошибка


1-98137
AndreyS
2002-09-17 14:26
2002.09.30
Какой инсталятор лучше?


1-98222
#Deus
2002-09-18 19:44
2002.09.30
Image


1-98051
MC TOL
2002-09-17 12:43
2002.09.30
Обман триальной программы.





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский