I want to write an output file with some information in Netlogo. It works fine so far but i wonder if i can write strings without quotation marks. It would help me alot in analysing my data. I could use another programm to delete the quotation marks but i would like to generate the file without them if its possible.
For example: i want to generate the output:
2_100_1 / 0.05081157374735357
3_100_1 / 0.09989594172736732
but i get the output
"2_100_1 / 0.05081157374735357"
"3_100_1 / 0.09989594172736732"
The problem seems to be that i use word, but i have no idea how i can fix this.
Any help is appreciated
file-write (word frequenz "_" transferrate "_" dangerradius " / " (overall-wait / ticks))
You can use file-print instead.
From the Netlogo Dictionary:
file-write outputs quotes around strings.
file-write value This command will output value, which can be a number,
string, list, boolean, or nobody to an opened file, not followed by a
carriage return (unlike file-print and file-show).
This agent is not printed before the value, unlike file-show. Its
output also includes quotes around strings and is prepended with a
space. It will output the value in such a manner that file-read will
be able to interpret it.
Note that this command is the file i/o equivalent of write, and
file-open needs to be called before this command can be used.
file-print:
file-print value Prints value to an opened file, followed by a
carriage return.
This agent is not printed before the value, unlike file-show.
Note that this command is the file i/o equivalent of print, and
file-open needs to be called before this command can be used.
See also file-show, file-type, file-write, and Output (programming
guide).
Related
I have a substitution to make in a Perl script, which I do not seem to get working. I have a string in a text file which has the form:
T+30H
The string T+30H has to be written in many files and has to change from file to file. It is two digits and sometimes three digits. First I define the variable:
my $wrffcr=qr{T+\d+H};
After reading the file containing the string, I have the following substitution command (starting with the file capture)
#scrptlines=<$NCLSCRPT>;
foreach $scrptlines (#scrptlines) {
$scrptlines =~ s/$wrffcr/T+$fcrange2[$jj]H/g;
}
$fcrange2[$jj] is defined and I confirm its value by printing its value just before the above 4 lines of code.
print "$fcrange2[$jj]\n";
When I run my script, nothing changes for this particular substitution. I suspect it is to do with the way I define the string to be substituted.
I will appreciate any assistance.
Zilore Mumba
Watch out for the first + in my $wrffcr=qr{T+\d+H};. It'll make it match 1 or more Ts, not T followed by a +. You probably want
my $wrffcr=qr{T\+\d+H};
I'm creating a PowerShell script that will assemble an HTTP path from user input. The output has to convert any spaces in the user input to the product specific codes, "%2F".
Here's a sample of the source and the output:
The site URL can be a constant, though a variable would be a better approach for reuse, as used in the program is: /http:%2F%2SPServer/Projects/"
$Company="Company"
$Product="Product"
$Project="The new project"
$SitePath="$SiteUrl/$Company/$Product/$Project"
As output I need:
'/http:%2F%2FSPServer%2FProjects%2FCompany%2FProductF2FThe%2Fnew%2Fproject'
To replace " " with %20 and / with %2F and so on, do the following:
[uri]::EscapeDataString($SitePath)
The solution of #manojlds converts all odd characters in the supplied string.
If you want to do escaping for URLs only, use
[uri]::EscapeUriString($SitePath)
This will leave, e.g., slashes (/) or equal signs (=) as they are.
Example:
# Returns http%3A%2F%2Ftest.com%3Ftest%3Dmy%20value
[uri]::EscapeDataString("http://test.com?test=my value")
# Returns http://test.com?test=my%20value
[uri]::EscapeUriString("http://test.com?test=my value")
For newer operating systems, the command is changed. I had problems with this in Server 2012 R2 and Windows 10.
[System.Net.WebUtility] is what you should use if you get errors that [System.Web.HttpUtility] is not there.
$Escaped = [System.Net.WebUtility]::UrlEncode($SitePath)
The output transformation you need (spaces to %20, forward slashes to %2F) is called URL encoding. It replaces (escapes) characters that have a special meaning when part of a URL with their hex equivalent preceded by a % sign.
You can use .NET framework classes from within Powershell.
[System.Web.HttpUtility]::UrlEncode($SitePath)
Encodes a URL string. These method overloads can be used to encode the entire URL, including query-string values.
http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx
I’ve written script that contains numerous hotkeys (general structure is as below). I would like to create another one that when pressed displays a list of all of the hotkeys and their corresponding descriptions that the script contains in a nice, formatted table.
The formatting and display are tenuous since AutoHotkey’s output is limited to message-boxes, but possible. More problematic is getting the hotkeys and corresponding descriptions.
The hotkeys all call the same function with different arguments. I considered adding a variable to the function so that depending on the value, the function either performs the normal function when triggered by the normal hotkeys, or builds a string or something when triggered from the special display hotkey.
I cannot figure out a way to programmatically access the script’s hotkeys at all. I checked the docs and there don’t seem to be any A_ variables that can be used for this purpose, nor does the Hotkey command lend itself well (it can be used to test if a hotkey exists, but looping through the innumerable combinations is, at best, tedious).
Failed attempts:
I tried using Elliot’s suggestion of parsing the script itself (replacing the path with %A_ScriptFullPath%, and while it does work for a raw script, it does not when the script is compiled
I tried assigning the entire hotkey section of the script to a variable as a continuation section and then parsing the variable and creating hotkeys using the Hotkey command. This worked well right up until the last part because the Hotkey command cannot take arbitrary commands as the destination and requires existing labels.
The ListHotkeys command is not applicable because it only displays the hotkeys as plain text in the control window.
Does anyone know how I can display a list of the hotkeys and either their corresponding arguments or comments?
Example script:
SomeFunc(foobar)
{
MsgBox %foobar%
}
!^#A::SomeFunc("a") ; blah
^+NumpadMult::SomeFunc("c") ; blivet
^+!#`::SomeFunc("b") ; baz
^#Space::SomeFunc("d") ; ermahgerd
…
Example desired “outputs”:
C+A+ W+ A a | C+ S+ NumpadMult b
------------------+----------------------
C+A+S+W+ ` c | C+ W+ Space d
or
Ctrl Alt Shift Win Key Action
-----------------------------------------
× × × A blah
× × NumpadMult baz
× × × × ` blivet
× × Space ermahgerd
etc.
The only thing I can think of is to read each line of your script individually and parse it. This code reads your script (script.ahk) one line at a time and parses it. This should get you started. Additionally, you could parse the line to check for the modifiers as well.
Loop
{
FileReadLine, line, C:\script.ahk, %A_Index%
if ErrorLevel
break
If Instr(line, "::")
{
StringSplit, linearray, line, ::,
key := linearray1
StringSplit, commandarray, linearray3, `;
action := commandarray2
hotkeyline := "key: " . key . "`tAction: " . action
final .= hotkeyline . "`r"
}
}
msgbox % final
return
I found a solution. It is not perfect (or ideal), and hopefully a proper, built-in method will become available in the future, but it works well (enough) and for raw and compiled scripts.
What I did was to use the FileInstall command which tells the compiler to add a file to the executable (and extract it when run).
Sadly, the FileInstall command will not allow the use of variables for the source file, so I cannot simply include the script itself (FileInstall, %A_ScriptFullPath%, %A_Temp%\%A_ScriptName%, 1).
As a work-around, I ended up extracting all of the desired hotkeys to a second file which I then parse as Elliot suggested, then delete, and #Include at the end of my script (it must be at the end since hotkeys will terminate the autoexecute section).
;;;;; Test.ahk ;;;;;
; Add hotkey file to executable and extract to Temp directory at runtime
FileInstall, Hotkeys.ahk, %A_Temp%\Hotkeys.ahk, 1
Loop
{
;Read a line from the extracted hotkey script and quit if error
FileReadLine, line, %A_Temp%\Hotkeys.ahk, %A_Index%
if ErrorLevel
break
;Trim whitespace
line=%line%
; Parse the line as in Elliot’s answer, but with tweaks as necessary
ParseHotkey(line)
…
}
FileDelete, %A_Temp%\Hotkeys.ahk ; Delete the extracted script
DisplayHotkeys() ; I ended up bulding and using a GUI instead
#Include, Hotkeys.ahk ; It is included at compile-time, so no A_Temp
;;;;; Hotkeys.ahk ;;;;;
z::MsgBox foo
y::MsgBox bar
Powershell tab expansion functions take 2 parameters, the line so far, and the "current word". The function should return a replacement for the current word.
From experiment, it seems to me that the current word is passed to the function without any quotes, and the returned word is inserted into the line with the same quoting as the original. So, for example, if I type
PS> foo "bar"<TAB>
I will get the string bar passed to my tab expansion function (without quotes), and my returned value will be placed back on the line in double quotes.
This behaviour causes problems in certain cases. For example, partial completion of file names, where I might type C:\Pro<TAB> to get "C:\Program Files", but I then need to delete the final quote to expand further (say, by typing \Micro and then hitting TAB again.
Also, returning an expanded value containing quotes can be very messy:
PS> function TabExpansion($line, $lastword) {
PS> "looks like '" + $lastword + "' when quoted"
PS> }
PS>
PS> Silly 'example'<TAB>
This results in unbalanced quotes.
Is there any way of avoiding or working around this behaviour?
Paul.
First off, this is not true:
This behaviour causes problems in
certain cases. For example, partial
completion of file names, where I
might type C:\Pro to get
"C:\Program Files", but I then need to
delete the final quote to expand
further (say, by typing \Micro and
then hitting TAB again.
You can continue typing the \Micro after the quote and it will take care of it for you.
If you really need to return a value containing quotes, you can inject the escape character (`) into your string. Note that you will need to escape the escape character itself so it doesn't get eaten:
function TabExpansion($line, $lastword){
"looks like ``'" + $lastword + "``' when quoted"
}
After Tab expansion, your example will look like:
Silly "looks like `'example`' when quoted"
and the parser should have no problem with it.
I am building a website and I require quotation marks in a configuration value.
Example:
convert_arg = -resize "1000x1000>" -strip -trim +repage -density 72x72 -sampling-factor 4:2:0 -quality 70
This particular configuration item is the command-line arguments to call Imagemagick's convert utility. The quotation marks tell the command-line not to consider '>' as the pipe command. However, Zend appears to strip these characters from the value, so it tries to pipe the subsequent error to a file called -strip.
Can this be disabled or worked around? Thanks.
As this question hasn't been answered in a while, I figure I will respond with my work-around. It's not ideal, but it works and is not too difficult to implement.
It involves declaring a constant which will represent the quotation mark, as Zend_Config (Which uses the parse_ini_file() function) will interpret PHP constants.
In www/index.php we declare the constant:
// Define _Q to be a quotation mark
defined('_Q') || define('_Q', '"');
In application.ini we use the constant in place of quotation marks:
my.config.key = "my config value can now contain " _Q "quotation marks" _Q "!"
So now, in your code, the value of my.config.key is now:
my config value can now contain "quotation marks"!