| SexScripts : can SexScript read/write from/to other text files? - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=226 | Page 1 of 1 |
can SexScript read/write from/to other text files? |
cw3211025 [ Fri Jan 13, 2012 5:39 am ] |
|---|---|
can SexScript read from other text files? Is it inherent all functions of Groovy? |
|
Re: can SexScript read/write from/to other text files? |
doti [ Fri Jan 13, 2012 10:33 am ] |
|---|---|
Yes, I'll show you some code, but a lot of different things can be done. Which kind of text files are you thinking about ? Plain text ? .ini ? .xml ? .html ? ... |
|
Re: can SexScript read/write from/to other text files? |
cw3211025 [ Sat Jan 14, 2012 11:23 am ] |
|---|---|
txt and ini files please... Thanks! |
|
Plain text files |
doti [ Sat Jan 14, 2012 1:06 pm ] |
|---|---|
Here is some code to write into a text file, then read from it Code: //write 2 lines def fo = new File("test.txt") fo.write("first line") fo.append(System.getProperty("line.separator")) fo.append("second line") //read and show all lines def fi = new File("test.txt") def lines = fi.readLines() //"lines" is now a full list, use as you want for(def line : lines) { show(line) wait(1) } NB for specialist : I always avoid closures, I find them too complex for SexScripts. |
|
Ini files |
doti [ Sat Jan 14, 2012 1:23 pm ] |
|---|---|
Here is some code to write into a windows .ini file, then read from it Code: //write 2 lines in a section def fo = new org.ini4j.Wini() fo.put("section1", "key1", "value1") fo.put("section1", "key2", "value2") fo.store(new File("test.ini")) //read those 2 values def fi = new org.ini4j.Wini(new File("test.ini")) show(fi.get("section1", "key1") + " "+fi.get("section1", "key2")) Easy ? Send a thank you message to people behind ini4j |
|
Re: can SexScript read/write from/to other text files? |
cw3211025 [ Sun Jan 15, 2012 4:54 am ] |
|---|---|
yes, looks easy. Thanks. Where can I learn the comprehensive tutor of this language? is it all same to groovy? |
|
Re: can SexScript read/write from/to other text files? |
doti [ Sun Jan 15, 2012 10:31 am ] |
|---|---|
Yes, above code is main Groovy. |
|
Re: Plain text files |
Banjo [ Tue Mar 19, 2013 5:55 am ] |
|---|---|
doti wrote: Here is some code to write into a text file, then read from it Code: //read and show all lines def fi = new File("test.txt") def lines = fi.readLines() //"lines" is now a full list, use as you want for(def line : lines) { show(line) wait(1) } Is it possible to just have SexScripts display just one (specified) line from a text file? |
|
Re: can SexScript read/write from/to other text files? |
doti [ Tue Mar 19, 2013 9:11 am ] |
|---|---|
Because the line can have any size, you must read the full file, at least to the line you search. So add a numeric variable to count the lines. Example showing the 4th line : Code: def n = 0
for(def line : lines) { if(n==4) show(line) n++ } |
|
Re: can SexScript read/write from/to other text files? |
0385 [ Sun May 05, 2013 11:24 pm ] |
|---|---|
i'm not a coder, But if you want one specific line, Can't you use the ini file and have the line be a value and you call it with the key? Maybe use sections to have different subjects. Then it doesn't need to read the whole file. Just grab value from key. Doti, is there a reason why you didnt define the file name at the start when writing to the file but only later in the store bit? |
|
Re: can SexScript read/write from/to other text files? |
doti [ Mon May 06, 2013 7:35 pm ] |
|---|---|
0385 wrote: i'm not a coder, But if you want one specific line, Can't you use the ini file and have the line be a value and you call it with the key? Maybe use sections to have different subjects. Then it doesn't need to read the whole file. Just grab value from key. Yes (it'll work only with a ini file, not any text file) 0385 wrote: Doti, is there a reason why you didnt define the file name at the start when writing to the file but only later in the store bit? Not really, I think it works anyway, like this : Code: //write 2 lines in a section
def fo = new org.ini4j.Wini(new File("test.ini")) fo.put("section1", "key1", "value1") fo.put("section1", "key2", "value2") fo.store() |
|
| Page 1 of 1 | All times are UTC + 1 hour [ DST ] |