Recent

Author Topic: [SOLVED]Alternating Copy substring within a string  (Read 2786 times)

Peterkl

  • New Member
  • *
  • Posts: 22
[SOLVED]Alternating Copy substring within a string
« on: April 09, 2016, 10:02:21 pm »
Greetings guys,

I'm looking for a way to copy a substring within a string, but each time I copy the substring I want to copy 9 characters to 9 characters consecutively. Let me show you an example, it would be the best for you to understand.
Example :
var
stringm,line2 : string;
a:integer;
.......
for a := 1 to 10 do begin
line2:=copy(stringm,a,9);

So here I copy the substring, the first time it starts at position 1 and goes like this till 10 (cuz of the "a")
Now as I said I would like to copy 9 in 9 chars, which leaded me to ask you guys if there is a way that I can replace the "a" in the copy function for a "for loop" or something that advances 9 chars each time a substring is copied, please see the follow example.

var
stringm : string;
a:integer;
.......
for a := 1 to 10 do begin
line2:=copy(stringm,HERE THE VALUE HAS TO START AT 1 AFTER 9 AFTER 18 AFTER 27...ETC,9);

I hope u understood what I mean, if you have any question, just ask please. 
« Last Edit: April 09, 2016, 10:56:07 pm by Peterkl »

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1263
Re: Alternating Copy substring within a string
« Reply #1 on: April 09, 2016, 10:21:14 pm »
Code: [Select]
for a := 0 to 9 do begin
line2:=copy(stringm,(a*9)+1,9);
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Peterkl

  • New Member
  • *
  • Posts: 22
Re: Alternating Copy substring within a string
« Reply #2 on: April 09, 2016, 10:55:44 pm »
Code: [Select]
for a := 0 to 9 do begin
line2:=copy(stringm,(a*9)+1,9);

Simple maths :p thank you :)

 

TinyPortal © 2005-2018