PDA

View Full Version : string


max77
11-23-2005, 02:26 AM
hi!
two questions about string:

-i would like lo translate a number in a string, which command sholud I use?
-i need to search inside a string another one using "jolly" characters like ? e *. is it possible? how?

thank you!!!!!!!!!!!!!!!!!!!!

Michael Kahle
11-23-2005, 04:14 AM
First one is easy --> LET Abc (STR 14.234) returns a string
opposite is LET Xyz (VAL "12.123")

Second one --> don't know abaout it. Maybe it helps to use a combination of
'POS', 'SUBSTR', '=' ?

John Scheffel
11-23-2005, 08:55 AM
I've never heard the expression "jolly" characters, but I'm guessing it is the same as "wildcard" characters, meaning a character which can represent any character(s) in a search string. It comes from wildcards in poker which can used as any card in the deck. The ? can be any single character, and * can be one or more characters.

The only macro command I know of for searching strings is the POS command which Michael mentioned. I ran a quick test and it does not support the standard wildcard characters ? or *, it treats them as a standard character. The Programming Help for POS does not mention support for any wildcard characters.

As Michael indicated, it might be possible to write a custom macro which can do it, but I don't think there is a standard command or macro which does it.

Lim Chee Beng
11-23-2005, 05:09 PM
As what Michael and John suggested, to search substring within a string, I normally use the POS command as below. Wildcard does not seem to be allowed. However, wildcard is allowed in infotext operations.
(POS string1 string2)
The function returns the first position (non-zero integer) of string2 within string1. If string2 is not contained in string1, it returns 0.

max77
11-24-2005, 07:16 AM
Thank you!
It's true... wildcard are not allowed. i tried yesterday and it didn't work.If you try, you can also name a part using ? and * characters...it's allowed!
So...i'm gonna writing a macro for it.

Thank you again!

Darren
11-24-2005, 12:34 PM
There is a way of using wildcards against text - take a look at "FIND_AND_REPLACE" here: http://www.cocreateusers.org/macros/macro.htm

John van Doorn
11-24-2005, 02:22 PM
Hi,

Please have a look at the command MATCH

Returns 1 if the first string is matched by the pattern specified by the second string, otherwise returns 0. The pattern may contain wildcards as follows:


* Matches any string including the null string.


? Matches any single character.


[...] Matches any one of the enclosed characters. A pair of characters
separated by a hyphen (-) matches any character lexically between the
pair, inclusive. A NOT operator, !, can be specified immediately
following the left bracket to match any single character not enclosed
in the brackets.


\ Removes any special meaning of the following character.


Any other character matches itself.

Kind Regards,
John

Michael Kahle
11-25-2005, 01:01 AM
Wow, great, yes, really - still things to learn for CoCreate people as well ;-)

The command to use is MATCH:

MATCH string string ===> number


Returns 1 if the first string is matched by the pattern specified by the second string, otherwise returns 0. The pattern may contain wildcards as follows:


* Matches any string including the null string.


? Matches any single character.


[...] Matches any one of the enclosed characters. A pair of characters
separated by a hyphen (-) matches any character lexically between the
pair, inclusive. A NOT operator, !, can be specified immediately
following the left bracket to match any single character not enclosed
in the brackets.


\ Removes any special meaning of the following character.


Any other character matches itself.

max77
11-25-2005, 05:26 AM
Thank you!!!!!!!!!!!!!!!!!!!!!!!!

It's really great!
So now I don't have to loose time to write a custom macro for it!
thank you very much!!

John Scheffel
11-28-2005, 09:16 AM
Yet another macro command I wasn't aware of and have never used. This is what makes reading these forums worthwhile, every week I learn something new. It even seems to support a tiny bit of the regular expression syntax with the brackets.