Jump to content

use if function on array (lazarus)

asim1999

I am trying to check values in an array awhen a string is input and then they are converted to ascii values and stored in the array. Basically if a value is less than 65 the change that value to 65 and if a value is higher than 90 then change to 90

How do I do this?

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

What language?

But in general, I'd do something like this:

You should do the check within a [for loop] with going from [0 to array size-1].

 

I hope this is somewhere close to what you need...

 

 

 

Spoiler

CPU:Intel Xeon X5660 @ 4.2 GHz RAM:6x2 GB 1600MHz DDR3 MB:Asus P6T Deluxe GPU:Asus GTX 660 TI OC Cooler:Akasa Nero 3


SSD:OCZ Vertex 3 120 GB HDD:2x640 GB WD Black Fans:2xCorsair AF 120 PSU:Seasonic 450 W 80+ Case:Thermaltake Xaser VI MX OS:Windows 10
Speakers:Altec Lansing MX5021 Keyboard:Razer Blackwidow 2013 Mouse:Logitech MX Master Monitor:Dell U2412M Headphones: Logitech G430

Big thanks to Damikiller37 for making me an awesome Intel 4004 out of trixels!

Link to comment
Share on other sites

Link to post
Share on other sites

What language?

But in general, I'd do something like this:

You should do the check within a [for loop] with going from [0 to array size-1].

I hope this is somewhere close to what you need...

The language is pascal (lazarus is the name of the ide I think)

CPU: Intel 3570 GPUs: Nvidia GTX 660Ti Case: Fractal design Define R4  Storage: 1TB WD Caviar Black & 240GB Hyper X 3k SSD Sound: Custom One Pros Keyboard: Ducky Shine 4 Mouse: Logitech G500

 

Link to comment
Share on other sites

Link to post
Share on other sites

The language is pascal (lazarus is the name of the ide I think)

Ah okay, I never used pascal.

 

Spoiler

CPU:Intel Xeon X5660 @ 4.2 GHz RAM:6x2 GB 1600MHz DDR3 MB:Asus P6T Deluxe GPU:Asus GTX 660 TI OC Cooler:Akasa Nero 3


SSD:OCZ Vertex 3 120 GB HDD:2x640 GB WD Black Fans:2xCorsair AF 120 PSU:Seasonic 450 W 80+ Case:Thermaltake Xaser VI MX OS:Windows 10
Speakers:Altec Lansing MX5021 Keyboard:Razer Blackwidow 2013 Mouse:Logitech MX Master Monitor:Dell U2412M Headphones: Logitech G430

Big thanks to Damikiller37 for making me an awesome Intel 4004 out of trixels!

Link to comment
Share on other sites

Link to post
Share on other sites

I know about the for loop, but don't know how to check specific values within the array as the array is dynamic, and so contains as many characters that were input in the string at the beginning

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

I am trying to check values in an array awhen a string is input and then they are converted to ascii values and stored in the array. Basically if a value is less than 65 the change that value to 65 and if a value is higher than 90 then change to 90

How do I do this?

if( arr[index] < 65 )  arr[index] = 65else if( arr[index] > 90 )  arr[index] = 90

I wonder how you're gonna handle numbers between 65 and 90 inclusive. Just leave it?

 

Dunno how to code in Pascal, never tried it but if you're asking for the logic, there you go xD

| CPU: Ryzen 5 3600 | MoBo: MSI B450 Tomahawk Max | RAM: T-Force Delta RGB (2x8) 16GB 3200MHz (Black) | GPU: Gigabyte GTX 1660 Ti OC | Case: NZXT H500 (Black) | HDD: WD Black 2TB + Seagate Barracuda 4TB | SSD: Crucial MX500 2TB | PSU: Seasonic GX-550 | Monitor: 3x Asus VC239H |

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I never used pascal, but if you are trying to convert from char to ascii value, looks like you can use ORD with follow @ZeferiniX logic.

 

Reference: http://borlandpascal.wikia.com/wiki/Char

 

Excuse my pascal, first time:

var i : integer;var s : string;var arr : array of integer; (* dynamic array *)begin  s := 'HELLO, WORLD!'; (* your input string *)  setLength(arr, byte(s[0])); (* set dynamic array to length of string *)    for i := 1 to byte(s[0]) do (* loop through input string *)  begin    if ( ord(s[i]) < 65 ) then        arr[i - 1] := 65    else if ( ord(s[i]) > 90 ) then        arr[i - 1] := 90    else        arr[i - 1] := ord(s[i]);  end;end.

This will clip characters to only A-Z, please note that this includes spaces, periods, etc.

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

×