PDA

View Full Version : How to read part of a string?



NewsArchive
04-28-2016, 01:36 AM
I want to perform a specific action if the first 2 characters of a
string are '\\'.

Thanks.

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:44 AM
> I want to perform a specific action if the first 2 characters of a
> string are '\\'.
>

IF myString[1:2] = '\\'
... action ...
END


If the string is ever less than 2 this will GPF

Tony Tetley

NewsArchive
04-28-2016, 01:45 AM
You can do that in SB?

Not seeing that this syntax works there.

Thanks Tony

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:45 AM
This is what I ended up doing. Not sure if it's the most bestest<g>

If %_SB_INSTALLDIR% Does Not Equal "%JS_DATA_LOCATION%" Then
Set Variable %JS_PATH_UNC_CHECK% to
FUNCTION:Mid(%JS_DATA_LOCATION%, 2, 1)
If %JS_PATH_UNC_CHECK% Equals "\\" Then
End
End

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:46 AM
> You can do that in SB?
>
> Not seeing that this syntax works there.

Umm. was not paying attention to which group you posted that question.

No idea if that works in SB, just color me embarrased!

Tony

NewsArchive
04-28-2016, 01:46 AM
Well, thanks for chiming in. :)

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:46 AM
Jeff,

> I want to perform a specific action if the first 2 characters of a
> string are '\\'.

Look at Handle String Operation.

--
Lee White

RPM Report Viewer.: http://www.cwaddons.com/products/rpm/
RPM Review........: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Report Faxing.....: http://www.cwaddons.com/products/afe/
---Enroll Today---: http://CWaddons.com

Creative Reporting: http://www.CreativeReporting.com

Product Release & Update Notices
http://twitter.com/DeveloperPLUS

Windows 8 brings us "The Oval, Bumper Car, Roller Coaster of Wait!"
And, now, Windows 10 brings us "The Inch Worm, Bumper Car of Wait!"

NewsArchive
04-28-2016, 01:47 AM
Thanks Lee. We're in business.

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:47 AM
Hi Jeff,

> Thanks Lee. We're in business.

Note that you can use Clarion DLLs in SB. I have a DLL that I wrote for
my installers to perform some actions back several years ago and that
has worked flawlessly. Back then I had problems getting search/replace
to work so I wrote that into the dll. Another thing it does is to
change the ,WIN32 to ,PASCAL for #RUNDLL in templates. It's just plain
..clw file that is compiled into a local dll.

Best regards,

--
Arnor Baldvinsson
Icetips Alta LLC

NewsArchive
04-28-2016, 01:47 AM
Hi Arnor -

We definitely use our own DLLs as support files. Thanks.

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:51 AM
Pretty OT here, but this source for GPF was new to me.

Does it mean that if the value of MyString STRING(20) is 'x',it will
GPF if I try to find MyString[1 : 2] ??

So the correct syntax would be:

If LEN(CLIP(MysTring))> 1
IF Mystring[1 : 2] = 'x\'
Message('Ok')
END
END


Best regards

Edvard Korsbæk

Den 27-04-2016 kl. 19:13 skrev Jeff Slarve:
> IF myString[1:2] = '\\'
>> ... action ...
>>END
>>
>>
>>If the string is ever less than 2 this will GPF

NewsArchive
04-28-2016, 01:51 AM
Hi Edvard -

He was referring to the size of the declaration.

For STRING(20), you wouldn't want to try string slicing
MySTring[1 : 50] :)

Jeff Slarve
www.jssoftware.com
Twitter free since Jan 11, 2016
I'll search help files & Google for you.

Grammar troll's, are the worse.

NewsArchive
04-28-2016, 01:52 AM
Hi Edvard,

> Pretty OT here, but this source for GPF was new to me.
>
> Does it mean that if the value of MyString STRING(20) is 'x',it will
> GPF if I try to find MyString[1 : 2] ??
>
> So the correct syntax would be:
>
> If LEN(CLIP(MysTring))> 1
> IF Mystring[1 : 2] = 'x\'
> Message('Ok')
> END
> END

What happens is that you are accessing memory directly. If you have:

S STRING(10)
CODE
Message(S[1 : 11])

you are accessing memory outside of the memory occupied by S. If you
try to do something like:

S[11] = 'A'

you would probably get a GPF because you are writing to memory that
belongs to something else. Reading might not cause a GPF, but writing
probably will. String slicing is the same as accessing an array and if
you compile with array bounds checking turned on, it will tell you at
runtime and terminate your program.

So if you are accessing arrays or string slicing you should always make
sure that you do not go outside the bounds of the array or string. That
means not accessing S[0] also!

You can use LEN() for strings or MAXIMUM() for arrays to make sure you
are always within bounds.

Best regards,


--
Arnor Baldvinsson
Icetips Alta LLC

NewsArchive
04-28-2016, 01:53 AM
Hi Jeff,

> I want to perform a specific action if the first 2 characters of a
> string are '\\'.

You have several different options. But I would use the "Left" String
Operation. See attached screenshot.

Friedrich