Recent

Author Topic: What is this example trying to say?  (Read 3722 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
What is this example trying to say?
« on: February 15, 2018, 09:56:05 pm »
Code: Pascal  [Select][+][-]
  1. Program Example79;
  2.  
  3. { This program demonstrates the RightStr function }
  4.  
  5. Uses sysutils;
  6.  
  7. Begin
  8.   Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',20));
  9.   Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',15));
  10.   Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',1));
  11.   Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',200));
  12. End.

I don't get it. Found this while trying to find some way of extracting info from a string.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: What is this example trying to say?
« Reply #2 on: February 15, 2018, 10:06:01 pm »
Run it. Compare the output with the numbers given as parameters.

balazsszekely

  • Guest
Re: What is this example trying to say?
« Reply #3 on: February 15, 2018, 10:07:38 pm »
Take a look at the attached image.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: What is this example trying to say?
« Reply #4 on: February 15, 2018, 10:26:52 pm »
https://www.freepascal.org/docs-html/rtl/sysutils/rightstr.html

Yea; that's where I got it from and didn't understand it.

I guess I could build a program and run it.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: What is this example trying to say?
« Reply #5 on: February 15, 2018, 10:33:16 pm »
Take a look at the attached image.

Quote
If Count is larger than the actual length of S only the real length will be used.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: What is this example trying to say?
« Reply #6 on: February 15, 2018, 10:44:03 pm »
I guess I could build a program and run it.
This is no effort at all: Click "File" > "New" and select "Program" from the "Project" node in the left tree.  Since the code in post #1 is a complete program (it begins with "Program" and ends with "end.") copy the code from the forum page into the clipboard. Return to Lazarus, select the entire auto-generated code by pressing  CTRL+A and paste the copied code from to clipboard into the Lazarus editor window. Press F9 to run. - That's all.
« Last Edit: February 22, 2018, 09:03:12 am by wp »

balazsszekely

  • Guest
Re: What is this example trying to say?
« Reply #7 on: February 15, 2018, 10:48:57 pm »
@rvk
I meant it as a funny illustration and apparently I failed miserably.  :D
Quote
If Count is larger than the actual length of S only the real length will be used.
It's obvious(in my opinion) that you cannot copy more then the actual length of the string.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: What is this example trying to say?
« Reply #8 on: February 15, 2018, 10:55:16 pm »
Quote
If Count is larger than the actual length of S only the real length will be used.
It's obvious(in my opinion) that you cannot copy more then the actual length of the string.
Ah, well, this is the Beginners-subforum so I wouldn't be so sure it's obvious to all those beginners ;)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: What is this example trying to say?
« Reply #9 on: February 15, 2018, 11:14:37 pm »
Ok I got it. But, IMO this it's a lousy example.

I was reading an example on the form and in the comments section it said something like "this is very similar to the C function xyx.

I'm think I don't know C, I'm trying to learn Pascal. Should I learn C first? Then I would understand what this is trying to say.

Oh well. The hardest 3 years of my life was 3rd grade.
 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: What is this example trying to say?
« Reply #10 on: February 16, 2018, 05:20:30 am »
Ok I got it. But, IMO this it's a lousy example.

I was reading an example on the form and in the comments section it said something like "this is very similar to the C function xyx.

I'm think I don't know C, I'm trying to learn Pascal. Should I learn C first? Then I would understand what this is trying to say.

Oh well. The hardest 3 years of my life was 3rd grade.
 
No, you don't have to. What's so hard about understanding the description:
Quote
RightStr returns the Count rightmost characters of S. It is equivalent to a call to Copy(S,Length(S)+1-Count,Count).
? Just substitute the variables with actual values and it's plain english.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: What is this example trying to say?
« Reply #11 on: February 16, 2018, 07:28:35 am »
What's so hard about understanding the description:

Reading the firstmost description  :D
Quote
Return a number of characters from a string, starting at the end.

Perhaps it is because English isn't my native tongue but, at first glance (acting noob) and taking the following line:
Code: [Select]
Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',5));
would mean write out "zyxwv"

Or is that too far fetched ?

Julius7

  • New Member
  • *
  • Posts: 19
Re: What is this example trying to say?
« Reply #12 on: February 22, 2018, 07:59:06 am »

RightStr returns the Count rightmost characters of S. It is equivalent to a call to Copy(S,Length(S)+1-Count,Count).

If Count is larger than the actual length of S only the real length will be used.


See also


LeftStr
 Return a number of characters starting at the left of a string.
 

Trim
Trim whitespace from the ends of a string.
 

TrimLeft
Trim whitespace from the beginning of a string.
 

TrimRight
Trim whitespace from the end of a string.

:)

thks

js

 

TinyPortal © 2005-2018