1. Tracy Lamb
  2. PowerBuilder
  3. Tuesday, 4 June 2024 15:27 PM UTC

Wondering how to write the match clause so it finds the first non-numeric value.  This algorithm is finding the first a-z character, but if the first non-numeric character is a special character, it doesn't work.

for li_x = 1 to li_length
	ls_char = Mid( as_nominal, li_x, 1)
	lb_match = Match(ls_char, "[A-Za-z]") 
	if lb_match then
		cbx_units.checked = true
		ddlb_units.text = Trim(Mid(as_nominal, li_x))
		sle_nominal.text = Trim(Left(as_nominal, li_x - 1))
		li_x = li_length + 1
		exit
	end if
NEXT

For example, the string passed in is "1,000 °C".  The algorithm is finding the C, but not the °.  I tried  lb_match = Match(ls_char, "[^0-9]") but that sees the comma as a non-digit.

TIA,
~~~Tracy

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 4 June 2024 15:47 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Tracy -

I've not tested this, but try the Match function using "^[^0-9\,]+$" as the match pattern. the "\," specifies the comma as a character that is to be recognized. I always use the "\" escape when my match pattern includes non-alphanumeric characters.

Best regards, John

Comment
  1. John Fauss
  2. Tuesday, 4 June 2024 16:07 PM UTC
So.... Add the decimal point character: ^0-9\,\.
  1. Helpful 2
  1. Tracy Lamb
  2. Tuesday, 4 June 2024 19:40 PM UTC
Thanks! Didn't know how interpret the match condition, lol! I do now!

  1. Helpful
  1. John Fauss
  2. Wednesday, 5 June 2024 01:34 AM UTC
You're welcome! The PB Help topic on the Match function does a reasonably good job of explaining the expression options and includes several examples - It might be worth a little of your time to examine it carefully.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 4 June 2024 19:04 PM UTC
  2. PowerBuilder
  3. # 1

Nothing to do with this question, but I don't really see the use of the Match function. Maybe I've used it twice in 30 years. The problem for me, is that it only returns true or false, but doesn't return the position in which your search pattern has been found.

(sorry for my rant).

Comment
  1. John Fauss
  2. Wednesday, 5 June 2024 01:53 AM UTC
I think it depends on each person's needs, Miguel. Myself, I've used the Match function many times in 30 years of slinging PowerScript code - not ALL the time, mind you, but enough to get reasonably familiar and comfortable with using it. At the same time, there's got to be quite a bit in PB that I've NEVER used. I maintain that many or most of the "tools" a developer needs are either provided or can usually be created with a little effort.

Yes, admittedly, the Match function only returns true or false, but that is because it was designed to only determine if the contents of a string matches a pattern or not. If you have a need for something more robust as you described, create it, then please consider sharing it with the Community (as I know you have done many times in the past). Cheers!
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 5 June 2024 06:48 AM UTC
haha, yes, the function that always helps me out is "Pos()"

regards
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 5 June 2024 06:49 AM UTC
and yes, I know that it doesn't allow you to use a regex expression.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.