It is currently Thu Jun 22, 2017 1:33 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Problem with dollar sign
Unread postPosted: Wed Apr 05, 2017 9:51 am 
Offline

Joined: Sat Dec 26, 2015 8:37 pm
Posts: 30
Is there a problem with having a dollar sign in a string?

Specifically, a$ = word$("A $B",1,"$") returns "A $B" instead of "A ",
and b$ = word$("A $B",1,"$") returns "" instead of "B"


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Wed Apr 05, 2017 10:17 am 
Offline

Joined: Sat Mar 11, 2017 5:49 am
Posts: 31
Hi

Try this
a$ = word$("A$B",1,"\\$")
a$ = word$("A$B",2,"\\$")

Regards
Danny


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Wed Apr 05, 2017 10:38 am 
Offline

Joined: Sat Dec 26, 2015 8:37 pm
Posts: 30
Danny,
Thank you. That works. I will recommend that this be included in the manual.
Robert


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Wed Apr 05, 2017 10:47 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 659
Location: UK
rrioja wrote:
Is there a problem with having a dollar sign in a string?

Specifically, a$ = word$("A $B",1,"$") returns "A $B" instead of "A ",
and b$ = word$("A $B",1,"$") returns "" instead of "B"

I think that where the manual says:
Quote:
This function {Word$} is similar to the Split command. See Split for a note about Regular Expressions.
that is intended to say that Word$ uses regular expressions. This is more explicit here (about Trim$):
Quote:
As with the WORD$() function and the SPLIT command, the <test_exp> is a regular expression. See Split for a note about Regular Expressions.

The "Note" in question is:
Quote:
Note: The <test_sexp> is actually a Regular Expression. If you are not getting the results that you expect from the <test_sexp> then you should examine the rules for Regular Expressions at: http://developer.android.com/reference/java/util/regex/Pattern.html

There you will find that "$" is a special character that needs "escaping" to use as itself.

HTH, Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Thu Apr 06, 2017 1:14 pm 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2802
Location: Colorado, U.S.
Yes, what Mike said.

'$' means "end of string". Similarly, '^' means "beginning of string" (or "negation" inside brackets). Also, '.' means "any character", "*" means "zero or more repetitions", '+' means "one or more repetitions, and '?' means . If you get used to regular expressions, you learn to be careful with all of these characters:
\ . [ ] { } ( ) * + - ? ^ $ |

The other thing you have to know is which BASIC! commands and functions use regular expressions. There are not many.
SPLIT and SPLIT.ALL
TRIM$()/LTRIM$()/RTRIM$() and WORD$()

Note that REPLACE$() does NOT use regular expressions -- that always surprises me a little.

- Marc


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Fri Apr 07, 2017 10:19 am 
Offline

Joined: Sat Dec 26, 2015 8:37 pm
Posts: 30
Why even have regular expressions? How does that make these commands any better or easier to use? Other languages/compilers/interpreters don't use regular expressions as parameters for their functions, without any problems. It just seems to me that the use of regular expressions in some functions just makes life more complicated.

Maybe it would be better if the default is a simple string expression, but if you want to use a regular expression it could be specified by some modifier. For example "a$a" is a string but #"a$a" is a regular expression because it is preceded by some unique identifier.

Robert


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Fri Apr 07, 2017 11:29 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5537
Location: Paris, France
rrioja wrote:
Other languages/compilers/interpreters don't use regular expressions

Android Java does (on which RFO-BASIC! is based)

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Fri Apr 07, 2017 2:32 pm 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 659
Location: UK
rrioja wrote:
... Other languages/compilers/interpreters don't use regular expressions as parameters for their functions, without any problems.

Even run-of-the-mill programs such as Microsoft Word and OpenOffice offer editing based on equivalent to regular expressions, though admittedly as non-default options.

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Problem with dollar sign
Unread postPosted: Sun Apr 09, 2017 2:49 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 356
We could think about it.
An optional parameter at the end.
1 for regular expressions
0 for no regular expressions
Default is 1

/Gregor


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred