STRIP FUNCTION

Discussions about CSEntry
Post Reply
segxy4manu
Posts: 40
Joined: August 31st, 2016, 5:51 pm

STRIP FUNCTION

Post by segxy4manu »

Good day folks,

Please I need a help on this.... I used a QR code to scan an with a generated QRCode in Alphanumeric.
I need to strip out the alpha from the numeric into another field
i.e the QR code scan is "NGR12367" I want to extract only the 12367 without striping NGR in a new field like a concate function.

Thanks.
sherrell
Posts: 405
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: STRIP FUNCTION

Post by sherrell »

If you know you will have a single block of numerics, then you can use the pochar function to find the first number, and use a loop to find the endpoint, as below:
string test = "NGR12367";

numeric firstNumber = poschar ("0123456789", test);
numeric index = firstNumber;

while test[index] in "0":"9" do
  inc
(index);
enddo;

errmsg ("numeric string found in positions %d to %d", firstNumber, index-1);
segxy4manu
Posts: 40
Joined: August 31st, 2016, 5:51 pm

Re: STRIP FUNCTION

Post by segxy4manu »

Thanks for your reply
But this will work if only the QRCode is known ....
But in this case the QRcode to be scan is not know and the combination of the numeric after the NGR wouldn't be known
so to use that
string test = "NGR12367"
would not work sir.
Thanks for the promot help
justinlakier
Posts: 210
Joined: November 21st, 2022, 4:41 pm

Re: STRIP FUNCTION

Post by justinlakier »

Hello,

The example code that Sherrell gives will work for any QR code you plug into it, not just "NGR12367", so long as the QRCode follows the pattern of a set of letters followed by a set of numbers. In your own code, rather than using

Code: Select all

string test = "NGR12367";
you may need to replace it with

Code: Select all

string test = $;
or something else. We do not know how your code is set up, you will need to do the finishing touch to modify the example with your own variables.

If you examine the code Sherrell gave, you will see that it uses PosChar() to find the position of the first numeric character of the QRcode (in 0-9), then uses a while loop to find the position of the last numeric character in the QRcode (in 0-9), and gives you an error message with the start and end points of this numeric string. You will have to use SubString Expressions in order to collect this numeric substring from the full string and place it somewhere else.

If you have a more complicated code that does not have a single numeric chunk, but has interspersed letters and numbers, you may have to modify the given code. You can do a While loop that goes over every character in the QRcode string, and if the current character is numeric (in "0":"9") places this character onto a new result string using concat. This will end with a result string containing all the numerics from your original string, and you can convert this to a normal numeric using ToNumber.

Hope this helps,
Justin
segxy4manu
Posts: 40
Joined: August 31st, 2016, 5:51 pm

Re: STRIP FUNCTION

Post by segxy4manu »

Thanks to @sherrell and @justinlakier
I was able to use your codes and suggestion with some other turn around to get the desire outcome.

I well appreciated.
Post Reply