music
OSdata.com: programming text book 

OSdata.com

strings

summary

    This subchapter looks at strings.

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating

Google

stub section

    This subchapter is a stub section. It will be filled in with instructional material later. For now it serves the purpose of a place holder for the order of instruction.

    Professors are invited to give feedback on both the proposed contents and the propsed order of this text book. Send commentary to Milo, PO Box 1361, Tustin, California, 92781, USA.

strings

    This subchapter looks at strings.

Ada

    “42.1/2 The predefined standard library packages provide facilities such as string manipulation, containers of various kinds (vectors, lists, maps, etc.), mathematical functions, random number generation, and access to the execution environment.” —:Ada-Europe’s Ada Reference Manual: Introduction: Language Summary See legal information

    “2 Finally, a predefined environment of standard packages is provided, including facilities for, among others, input-output, string manipulation, numeric elementary functions, and random number generation.” —:Ada-Europe’s Ada Reference Manual: Section 1: General See legal information

functions

BASIC    VAL(x) — BASIC library function that returns the integer value of a character string or expression. Note that some versions of VAL will strip out leading blanks..

BASIC    LEN(x) — BASIC library function that returns the length of a string..

BASIC    MID$(string,n1,n2) — BASIC library function that returns the specified number of characters (n2) from starting from the specified number of characters (n1) from the leftmost character in the string variable or expression string...

BASIC    LEFT$(string,n) — BASIC library function that returns the specified number of characters (n) from starting from the leftmost character in the string variable or expression string...
PostScript    anchorsearch(x) — PostScript operator. Finds two text strings, string and search, on the stack. Determines if the string search is the exact beginning of the string string. If it is, then it splits the string string into two parts, post (the remainder of the string after the matching part) and match (the part that matches search), placing them on the stack with the boolean value true. Otherwise it places the original string on the stack along with the boolean value false..

BASIC    RIGHT$(string,n) — BASIC library function that returns the specified number of characters (n) from starting from the rightmost character in the string variable or expression string...

BASIC    SPACE$(x) — BASIC library function that returns the a character string filled with the space character. The length of the string is specified by the expression x..

Stanford Perl essentials

    This [the following section until marked as end of Stanford University items] is document #108 [Essential Perl] in the Stanford CS Education Library --see http://cslibrary.stanford.edu/108/. This document is free to be used, reproduced, or sold so long as this paragraph and the copyright are clearly. Copyright 2000-2002, Nick Parlante, nick.parlante@cs.stanford.edu.

3. Strings

    Strings constants are enclosed within double quotes (") or in single quotes ('). Strings in double quotes are treated specially -- special directives like \n (newline) and \x20 (hex 20) are expanded. More importantly, a variable, such as $x, inside a double quoted string is evaluated at run-time and the result is pasted into the string. This evaluation of variables into strings is called “interpolation” and it’s a great Perl feature. Single quoted (') strings suppress all the special evaluation -- they do not evaluate \n or $x, and they may contain newlines.

    $fname = "binky.txt";
    $a = "Could not open the file $fname."; ## $fname evaluated and pasted in -- neato!
    $b = 'Could not open the file $fname.'; ## single quotes (') do no special evaluation

    ## $a is now "Could not open the file binky.txt."
    ## $b is now "Could not open the file $fname."

    The characters ‘$’ and ‘@’ are used to trigger interpolation into strings, so those characters need to be escaped with a backslash (\) if you want them in a string. For example:

    "nick\@stanford.edu found \$1".

    The dot operator (.) concatenates two strings. If Perl has a number or other type when it wants a string, it just silently converts the value to a string and continues. It works the other way too -- a string such as “42” will evaluate to the integer 42 in an integer context.

    $num = 42;
    $string = "The " . $num . " ultimate" . " answer";

    ## $string is now "The 42 ultimate answer"

    The operators eq (equal) and ne (not equal) compare two strings. Do not use == to compare strings; use == to compare numbers.

    $string = "hello";
    ($string eq ("hell" . "o")) ==> TRUE
    ($string eq "HELLO") ==> FALSE

    $num = 42;
    ($num-2 == 40) ==> TRUE

    The lc("Hello") operator returns the all lower-case version “hello”, and uc("Hello") returns the all upper-case version “HELLO”.

Fast And Loose Perl

    When Perl sees an expression that doesn’t make sense, such as a variable that has not been given a value, it tends to just silently pass over the problem and use some default value such as undef. This is better than C or C++ which tend to crash when you do something wrong. Still, you need to be careful with Perl code since it’s easy for the language to do something you did not have in mind. Just because Perl code compiles, don’t assume it’s doing what you intended. Anything compiles in Perl.

    This [the above section] is document #108 [Essential Perl] in the Stanford CS Education Library --see http://cslibrary.stanford.edu/108/. This document is free to be used, reproduced, or sold so long as this paragraph and the copyright are clearly. Copyright 2000-2002, Nick Parlante, nick.parlante@cs.stanford.edu.

end of Stanford Perl essentials

JOVIAL

    The following material is from the unclassified Computer Programming Manual for the JOVIAL (J73) Language, RADC-TR-81-143, Final Technical Report of June 1981.

    1.1.5 Built-In Functions

    The JOVIAL built-in functions provide advanced, specialized
    operations that are not covered by the JOVIAL operators.

         BYTE(c,i,n)    A string of n characters starting at the i'th
                        character of the character string c

    An example of the use of a built-in function is:

         C = BYTE("ABCDEF",2,3);

    The built-in functions extracts "BCD" from the string "ABCDEF".

    Chapter 1 Introduction, page 9

    1.1.5 Built-In Functions

    Two of the built-in functions, BIT and BYTE, can be used as
    pseudo-variables.  In that form, they appear as the target of an
    assignment, and are interpreted "backwards".  An example is:

         C = "ABCDEF";
         BYTE(C,2,3) = "XYZ";

    This assignment changes the second, third, and fourth characters
    of C to "XYZ".  The value of C after the assignment is therefore
    "AXYZEF".

    Chapter 1 Introduction, page 10

assembly language instructions

See also String and Character Instructions in Assembly Language

other

   “34. The string is a stark data structure and everywhere it is passed there is much duplication of process. It is a perfect vehicle for hiding information.” —Alan Perlis, Epigrams on Programming, ACM’s SIGPLAN Notices Volume 17, No. 9, September 1982, pages 7-13

   “106. It’s difficult to extract sense from strings, but they’re the only communication coin we can count on.” —Alan Perlis, Epigrams on Programming, ACM’s SIGPLAN Notices Volume 17, No. 9, September 1982, pages 7-13


free music player coding example

    Coding example: I am making heavily documented and explained open source code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action: www.musicinpublic.com/.

    Create your own copy from the original source code/ (presented for learning programming).


return to table of contents
free downloadable college text book

view text book
HTML file

Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.

previous page next page
previous page next page

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
Milo
PO Box 1361
Tustin, California 92781

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2010, 2012 Milo

    Created: November 1, 2010

    Last Updated: August 14, 2013


return to table of contents
free downloadable college text book

previous page next page
previous page next page