Jump to content

How to repeat a set string

asim1999

What I am trying to do is to repeat a set string for example: "comp" so it has as many letters as the input string, such as "Hello". so the other string will look like this: " compc". how do I do this in Lazarus and make it ignore spaces?

Current Rig:   CPU: AMD 1950X @4Ghz. Cooler: Enermax Liqtech TR4 360. Motherboard:Asus Zenith Extreme. RAM: 8GB Crucial DDR4 3666. GPU: Reference GTX 970  SSD: 250GB Samsung 970 EVO.  HDD: Seagate Barracuda 7200.14 2TB. Case: Phanteks Enthoo Pro. PSU: Corsair RM1000X. OS: Windows 10 Pro UEFI mode  (installed on SSD)

Peripherals:  Display: Acer XB272 1080p 240Hz G Sync Keyboard: Corsair K95 RGB Brown Mouse: Logitech G502 RGB Headhet: Roccat XTD 5.1 analogue

Daily Devices:Sony Xperia XZ1 Compact and 128GB iPad Pro

Link to comment
Share on other sites

Link to post
Share on other sites

Dude, please start adding what language you're talking about, instead of the IDE, prefferably in the title of the thread. Most people have no idea wtf "Lazarus" is.

Link to comment
Share on other sites

Link to post
Share on other sites

What I am trying to do is to repeat a set string for example: "comp" so it has as many letters as the input string, such as "Hello". so the other string will look like this: " compc". how do I do this in Lazarus and make it ignore spaces?

I don't do Lazarus (or Pascal), but is there a String.Length function of some sorts in it?

Might want to look that up.

 

After that .. Hmm.. There are different strategies after that.

You can repeat the word like 5 times and remove excess letters..

Or you can break apart the first word you have and let the program 'lay down letters' the amount of times of the other word's length..

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Dude, please start adding what language you're talking about, instead of the IDE, prefferably in the title of the thread. Most people have no idea wtf "Lazarus" is.

 

This.

 

Just use your brain and math(specifically division and modulo). This is pretty simple.

Link to comment
Share on other sites

Link to post
Share on other sites

This.

 

Just use your brain and math(specifically division and modulo). This is pretty simple.

 

^ That.

 

But here goes, this is my second time with pascal, no criticism please. I leave it to you to figure out how to ignore spaces. Possibly loop through input string and count number of non-spaces?

var input1, input2, output : string;var len1, len2, multiple, modulus, i : integer;begin  input1 := 'comp';  input2 := 'hello';  output := '';    len1 := byte(input1[0]);  len2 := byte(input2[0]);    multiple := len2 div len1; (* integer division *)  modulus := len2 mod len1;    (* repeat whole word *)  for i := 1 to multiple do  begin    output += input1;  end;    (* output last partial string *)  output += copy(input1, 0, modulus);    writeln(output);end.
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×