Help with text string

Help with text string

Anonymous
Not applicable
1,112 Views
4 Replies
Message 1 of 5

Help with text string

Anonymous
Not applicable

I have a variable "PanelNumber"

This may equal "123" or "A123" or "B123" or "C123" etc.. 

I want to look at the variable and if the first character of the string is a letter run subprogram "program1" or if the first character is a number then run subprogram "Program2"

 

Is this possible?  I am able to strip and return the first character, but unsure how to determine if its a letter of number.

 

Thank you in advance!!

0 Likes
Accepted solutions (2)
1,113 Views
4 Replies
Replies (4)
Message 2 of 5

Ranjit_Singh
Advisor
Advisor
Accepted solution

Many ways to do this. One example

(setq var_name "A123")
(if (wcmatch var_name "[0-9]*") "call prog2" "call prog1"))

or 

(setq var_name "A123")
(if (wcmatch var_name "#*") "call prog2" "call prog1"))
Message 3 of 5

Anonymous
Not applicable

This appears to work, but I have a follow up question..

 

Is it possible to set a variable that is equal to the first character? 

 

For instance.. "PanelNumber variable is P123, I want to (setq First_Char "P")

For instance.. "PanelNumber variable is X123, I want to (setq First_Char "X")

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

Is it possible to set a variable that is equal to the first character? 

 

For instance.. "PanelNumber variable is P123, I want to (setq First_Char "P")

....


Look into the (substr) function [= SUBSTRing from a longer one]:

(setq First_Char (substr PanelNumber 1 1))

Kent Cooper, AIA
Message 5 of 5

Anonymous
Not applicable

Thank you sir!!  Very much apperciated

0 Likes