how to test for a ' in an if condition
I am reading a file with read/lines e.g myLines: read/lines %file1.txt for each line myLines [ test if the first character is ' ] in the file there are lines that start with ' and some without. e.g of lines in the file:- ' insert something into table ' commit; how do I test that the first character is a ' ? I cannot get the syntax right. I tried :- if line/1 = ''' but got error. if line/1 = #''' but gets error. what is the correct syntax to use?
posted by: change last text 10-Dec-2016/22:39:05-8:00
You can use the pound symbol, or convert the character to a string: write %firstcharquote.txt {'adfs'^/qwer^/'uiop} x: read/lines %firstcharquote.txt foreach line x [ if line/1 = #"'" [ print rejoin ["Single quote starts: " line] ] ] x: read/lines %firstcharquote.txt foreach line x [ if (form line/1) = "'" [ print rejoin ["Single quote starts: " line] ] ] halt
posted by: Nick 11-Dec-2016/0:00:01-8:00
Thanks Nick. sorry there was a typo it is " (double quote sign) I thought I typed (double quote sign)
posted by: change last text 11-Dec-2016/8:22:48-8:00
It works the same for double quotes: R E B O L [] write %firstcharquote.txt {"adfs"^/qwer^/"uiop} x: read/lines %firstcharquote.txt foreach line x [ if line/1 = #"^"" [ print rejoin ["Double quote starts: " line] ] ] x: read/lines %firstcharquote.txt foreach line x [ if (form line/1) = {"} [ print rejoin ["Double quote starts: " line] ] ] halt You can get the character code for any key using this script: insert-event-func func [f e] [if e/type = 'key [print mold e/key] e] view layout [text "Type keys to see their character/keycode"]
posted by: Nick 11-Dec-2016/9:09:08-8:00
thanks Nick. it works. thanks also for hte script to get the character code for any key. very useful to have this. I will keep it safely in my toolbox.
posted by: change last text 11-Dec-2016/9:45:59-8:00
Take a look through http://re-bol.com/examples.txt I put most of my useful code examples over the years in there (most of it's also at http://business-programming.com, with explanations ;)
posted by: Nick 11-Dec-2016/19:15:42-8:00
thanks Nick. I went through the examples, they are very helpful, and straight to the point, exactly what i am looking for. thanks again.
posted by: change last text 12-Dec-2016/21:19:19-8:00
|