In BASIC I know of two instructions to print to the screen, PRINT, and WRITE, both of which automatically print strings with a newline at the end. I want to print a string without a newline. How can I do this? I'm using GW-BASIC.
Using PRINT with a semicolon will not print a new line:
10 REM The trailing semicolon prevents a newline
20 PRINT "Goodbye, World!";
Source: Rosettacode
Related
I'm new to lua and I'm trying to print an open curly bracket { in the output screen. I tried these ones:
print "%{"
print "\u123"
print "{{"
And there was no luck, but if I try the close bracket there's no problem and it prints }.
I'm wondering how may I figure it out.
print "{" Should do the job.
#lhf already sugested.
Is there a way to convert a quoted string to a multiline string?
Something like "This string \66 here" to [[This string \66 here]] since I would like to ignore the interpretation of escaped characters.
Lua 5.3 Reference Manual 3.1: Lexical Conventions
Literal strings can also be defined using a long format enclosed by
long brackets. We define an opening long bracket of level n as an
opening square bracket followed by n equal signs followed by another
opening square bracket. So, an opening long bracket of level 0 is
written as [[, an opening long bracket of level 1 is written as [=[,
and so on. A closing long bracket is defined similarly; for instance,
a closing long bracket of level 4 is written as ]====]. A long literal
starts with an opening long bracket of any level and ends at the first
closing long bracket of the same level. It can contain any text except
a closing bracket of the same level. Literals in this bracketed form
can run for several lines, do not interpret any escape sequences, and
ignore long brackets of any other level. Any kind of end-of-line
sequence (carriage return, newline, carriage return followed by
newline, or newline followed by carriage return) is converted to a
simple newline.
For convenience, when the opening long bracket is immediately followed
by a newline, the newline is not included in the string.
That's all you need to know about long strings.
It does not make much sense to convert a string that has been defined using quotes "some string" to a string like [[some string]] as both quotes and square brackets are not actually part of that string and the string itself is the same.
The only difference would be a leading newline which is ignored in square brackets or escape sequences which are not interpreted.
Quotes and square brackets are only part of the string if you have nested strings. In this case conversion also doesn't make much sense because you cannot nest strings with quotes like strings with brackets.
Maybe your whole approach is a bit off?
Do you look for something like this?
local db = "google"
local tbl = "accounts"
local where = "field = 'VALUE' AND TRUE"
local order = "id DESC"
local query = string.format([[
SELECT *
FROM `%s`.`%s`
WHERE %s
ORDER BY %s
]], db, tbl, where, order)
On The Lua Interpreter
>print("This is a string
>>spread over multiline")
stdin:1: unfinished string near '"This is a'
Since we know on the Lua interpreter we can finish a statement over mulitline
For eg
>a=2
>a=a+
>>1
This works perfectly
Again:
>print([[This is a multiline
>>string]])
This is a multiline
string
This works fine!! then why display error in the first print() statement??
Read the fine Reference Manual:
3.1 – Lexical Conventions
[…]
A short literal string can be delimited by matching single or double
quotes, and can contain the following C-like escape sequences: '\a' (bell),
'\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage
return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash),
'\"' (quotation mark [double quote]), and '\'' (apostrophe [single
quote]). A backslash followed by a line break results in a newline in the
string. The escape sequence '\z' skips the following span of white-space
characters, including line breaks; it is particularly useful to break and
indent a long literal string into multiple lines without adding the newlines
and spaces into the string contents. A short literal string cannot contain
unescaped line breaks nor escapes not forming a valid escape sequence.
[…]
Literal strings can also be defined using a long format enclosed by long
brackets. We define an opening long bracket of level n as an opening
square bracket followed by n equal signs followed by another opening
square bracket. So, an opening long bracket of level 0 is written as [[,
an opening long bracket of level 1 is written as [=[, and so on. A
closing long bracket is defined similarly; for instance, a closing long
bracket of level 4 is written as ]====]. A long literal starts with an
opening long bracket of any level and ends at the first closing long
bracket of the same level. It can contain any text except a closing
bracket of the same level. Literals in this bracketed form can run for
several lines, do not interpret any escape sequences, and ignore long
brackets of any other level. Any kind of end-of-line sequence (carriage
return, newline, carriage return followed by newline, or newline followed
by carriage return) is converted to a simple newline.
I am modifying a delphi app.In it I'm getting a text from a combo box. The problem is that when I save the text in the table, it contains a carriage return. In debug mode it shows like this.
newStr := 'Projector Ex320u-st Short Throw '#$A'1024 X 768 2700lm'
Then I have put
newStr := StringReplace(newStr,'#$A','',[rfReplaceAll]);
to remove the '#$A' thing. But this doesn't remove it.
Is there any other way to do this..
Thanks
Remove the quotes around the #$A:
newStr := StringReplace(newStr,#$A,'',[rfReplaceAll]);
The # tells delphi that you are specifying a character by its numerical code.
The $ says you are specifying in Hexadecimal.
The A is the value.
With the quotes you are searching for the presence of the #$A characters in the string, which aren't found, so nothing is replaced.
Adapted from http://www.delphipages.com/forum/showthread.php?t=195756
The '#' denotes an ASCII character followed by a byte value (0..255).
The $A is hexadecimal which equals 10 and $D is hexadecimal which equals 13.
#$A and #$D (or #10 and #13) are ASCII line feed and carriage return characters respectively.
Line feed = ASCII character $A (hex) or 10 (dec): #$A or #10
Carriage return = ASCII character $D (hex) or 13 (dec): #$D or #13
So if you wanted to add 'Ok' and another line:
Memo.Lines.Add('Ok' + #13#10)
or
Memo.Lines.Add('Ok' + #$D#$A)
To remove the control characters (and white spaces) from the beginning
and end of a string:
MyString := Trim(MyString)
Why doesn't Pos() find them?
That is how Delphi displays control characters
to you, if you were to do Pos(#13, MyString) or Pos(#10, MyString) then it
would return the position.
Wondering if it's possible to print a carriage return without a line feed in erlang? i.e. equivalent to printf("this will be replaced next time \r"); in C.
Had a look through the io:format() documentation and didn't see anything. It only seems to support ~n, equivalent to carriage return+line feed pair ('\n' in C).
Thx.
"\r" is a perfectly valid escape sequence in Erlang. So you can do just
io:format("\r").
Check the reference manual for other escape sequences.
You can use \r in a string for the return character so:
io:format("Counter value: ~b\r", [Counter])
This is also works for character constants, $\r, and in quoted atoms.
Doh. Answer came almost as soon as I posted. ~c enables printing of ASCII characters, so it's just a case of printing ASCII carriage return (13). e.g.
io:format("Counter value: ~b~c", [Counter,13])
Still interested in anything more elegant...
Thx.