Forum > Beginners

TString problem(Solved)

(1/3) > >>

JLWest:
I have a tstring which I believe looks like the following:
   $000000000658E5D8^: '51,40,45,44,44,40,'

I can't figure a way to extract the substrings '51', '40', '45', and '44' the first 4 sets.
The number will change all the time from 1 to 52
Is there a way to do this.
  Thanks

SymbolicFrank:
TStringList.CommaText

y.ivanov:
One of the possibilities:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  StrUtils;var  S, T: String;  I, N: Integer;begin  S :=  '51,40,45,44,44,40,';  I := 1;  N := 1;  while (I <= Length(S)) and (N <= 4) do  begin    // Extract the N-th (N=1..4) comma sep. string    T := ExtractSubstr(S, I, [',']);    WriteLn(N, '=', T);    Inc(N);  end;end. Why you don't use array of Integer instead?

Edit: Wait a minute, what is a tstring?

Ally:
Split is probably the easiest thing to do.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  i: Integer;  Row: String;  Parts: TStringArray;  S1, S2, S3, S4: String;begin  Row :=  '51,40,45,44,44,40,';  Parts := Row.Split(',');  S1 := Parts[0];  S2 := Parts[1];  S3 := Parts[2];  S4 := Parts[3];end;

Thaddy:
Yup, that's how I would do it. Good little example.

Navigation

[0] Message Index

[#] Next page

Go to full version