String: Difference between revisions

From Computer Science Wiki
No edit summary
No edit summary
Line 10: Line 10:


# this program would output the letter l (L) .  
# this program would output the letter l (L) .  
</syntaxhighlight>
</syntaxhighlight>


== Example ==
== Example ==
Line 19: Line 16:


=== PHP ===
=== PHP ===
Please read [http://php.net/manual/en/language.types.string.php the official PHP page regarding single quotes, double quotes, heredoc sytnax and nowdoc syntax]
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
<?php
<?php
$a = 1234.65; // decimal number
$a = "Hello World";
$a = -1234.54; // a negative number
?>
?>
</syntaxhighlight>
</syntaxhighlight>

Revision as of 05:30, 7 August 2017

Programming basics[1]

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable.[2].

Because strings are a sequence of characters, we can usually select them in the same way we can select elements from an array. For example:

myString = 'Hello World'
print(mystring[2])

# this program would output the letter l (L) .

Example[edit]

Here we encounter some different syntax rules. Programming languages define strings differently. Please do pay attention to the quotation marks, double quotation marks, and triple quotation marks.

PHP[edit]

Please read the official PHP page regarding single quotes, double quotes, heredoc sytnax and nowdoc syntax

<?php
$a = "Hello World";
?>

Python[edit]

  • Single quotes: 'allows embedded "double" quotes'
  • Double quotes: "allows embedded 'single' quotes".
  • Triple quoted: Three single quotes, """Three double quotes"""

Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.[3]

myString = 'Hello World'

Javascript[edit]

// decimal number:
var a = 1234.65; 
// a negative number:
var a = -1234.65;

Do you understand this?[edit]

Standards[edit]

  • Define the terms: variable, constant, operator, object.

References[edit]