Tern Paper of Data

Embed Size (px)

Citation preview

  • 8/3/2019 Tern Paper of Data

    1/28

    wertyuiopasdfghjklzxcvbnmqw

    tyuiopasdfghjklzxcvbnmqwerty

    pasdfghjklzxcvbnmqwertyuiop

    dfghjklzxcvbnmqwertyuiopasdf

    jklzxcvbnmqwertyuiopasdfghjk

    cvbnmqwertyuiopasdfghjklzxcv

    nmqwertyuiopasdfghjklzxcvbnwertyuiopasdfghjklzxcvbnmqw

    tyuiopasdfghjklzxcvbnmqwerty

    pasdfghjklzxcvbnmqwertyuiopdfghjklzxcvbnmqwertyuiopasdf

    jklzxcvbnmqwertyuiopasdfghjk

    cvbnmqwertyuiopasdfghjklzxcvnmqwertyuiopasdfghjklzxcvbn

    wertyuiopasdfghjklzxcvbnmqw

    tyuiopasdfghjklzxcvbnmrtyuiop

    Term Paper of Data StructureOn

    Operations on Strings

    DOS:12/19/2008

    Submitted By:

    Name: Shruti ThakurRoll no.: 10Reg.:3010070235

    Course: BCA-MCA Dual IntegratedSection: A

  • 8/3/2019 Tern Paper of Data

    2/28

    Operations on Strings 200

    8

    AcknowledgementI would like to express my gratitude to all those who gave me helping hand in completing this

    term paper. I want to thank my teacher Miss. Rajdeep Kaur for helping me whenever I needed it

    the most. My friends have also supported me in my work. I want to thank them all for their help,

    support, interest and valuable hints.

    2

  • 8/3/2019 Tern Paper of Data

    3/28

    Operations on Strings 200

    8

    Contents

    Topics Page no.

    Introduction 4-5

    Operations on Strings 6-26

    Conclusion 27

    References 28

    3

  • 8/3/2019 Tern Paper of Data

    4/28

    Operations on Strings 200

    8

    Introduction

    String is a sequence of characters enclosed in quotes. E.g. Hello

    String processing is one of the most important and most frequent applicationsof a computer

    Java recognizes this fact and therefore provides special support for strings to

    make their use convenient

    Every string is an instance of Javas built in String class, thus, Strings are

    objects.

    Declaration

    Like any object, a string can be created using new as in the following example:o String str1 = new String(Hello dear);

    However, as an extra support, Java allows String object to be created without

    the use of new, as in:

    o String str2=How are you;

    This is inconsistent with the way Java treats other classes.

    String objects are represented as a sequence of characters indexed from 0.

    Example: String greeting = Hello, World;

    H e l l o . W o R l d !

    0 1 2 3 4 5 6 7 8 9 10 11 12

    A common operation on Strings is extracting a substring from a a given string.

    Java provides two methods for this operation:

    Another special feature of Strings is that they are immutable. That is, once a string

    object is created, its content cannot be changed. For example, consider the following: String str1 = Hello World;

    str1 = str1.substring(4);

    Instead of changing the str1 object, another object is created. The former is garbage

    collected, thus, the reference to the former is lost.

    The fact that Strings are immutable allows the Java system to process Strings very

    efficiently.

    For example, consider the following:

    4

  • 8/3/2019 Tern Paper of Data

    5/28

    Operations on Strings 200

    8

    String str1 = Hello;

    String str2 = Hello;

    We would expect the following

    But in fact, this is what happens

    The Java system is smart enough to know that the two strings are identical and allocatessame memory location for the two objects

    5

  • 8/3/2019 Tern Paper of Data

    6/28

    Operations on Strings 200

    8

    Operations in String

    ABBREV

    Tests if one string is an abbreviation of another string. An abbreviation is a substring

    that starts at the beginning of a string. For example, 'auto' could be an abbreviation for

    'automobile'.

    Syntax:

    result = ABBREV(string, abbreviation, length)

    stringis the string (for which abbreviation may be an abbreviation).

    abbreviation is a possible abbreviation ofstring.

    length is the minimum length that abbreviation must be in order to beconsidered as an abbreviation. Iflength is omitted, there is no restriction upon

    abbreviation's minimum length (and therefore an empty string would beconsidered an abbreviation for any other string).

    Returns

    1 ifabbreviation is an abbreviation ofstring, or 0 if not.

    Notes

    ABBREV() is case sensitive, and leading/trailing spaces are not stripped off before

    the two strings are compared.

    Examples

    Example Use Output

    ABBREV('Foobar', 'Foo') 1

    ABBREV('Foobar', 'Foo', 4) 0 /* 'Foo' isn't at least 4 chars */

    ABBREV('Foobar', 'foo') 0 /* Different case - 'F' versus 'f' */

    6

  • 8/3/2019 Tern Paper of Data

    7/28

    Operations on Strings 200

    8

    CENTER

    Returns a string formatted to fit centered within a certain number of characters. Ifnecessary, the string's size is decreased to fit into that many characters, or pad

    characters are used to fill out the new string with the original string centered within

    the new string.

    Syntax:

    formatted = CENTER(string,length,padchar)

    stringis the original string (to format).

    length is the desired length of the final string. If length is less than the size ofthe original string, then characters will be deleted from the front and end of the

    string in order to fit the desired length. If length is greater than the size of the

    original string, then the original string will be centered within the new string

    andpadcharcharacters will be used to fill out the new string to the desiredlength. length must not be negative, nor have a fractional component -- it must

    be a positive whole number.

    padchar is the character to use for padding (if the original string is notalready >= the desired length). Ifpadcharis omitted, the default is a space

    character.

    Returns

    A copy of the original string extended to the desired length, with the original string

    centered within the new string, and padchars filling out the new string.

    Notes

    The original string is not altered. Only the returned value from CENTER is formatted.

    If length is an odd number, any extrapadcharis placed on the right-hand side of thecentered, original string.

    Examples

    Example Use Result

    CENTER('Foobar',10) ' Foobar '

    7

  • 8/3/2019 Tern Paper of Data

    8/28

    Operations on Strings 200

    8

    CENTER('Foobar',11) ' Foobar '

    CENTER('Foobar',3) 'oob'

    CENTER('Foobar',4) 'ooba'

    CENTER('Foobar',10,*) '**Foobar**'

    CHANGESTR

    Exchanges any occurence of one substring (within a given string) with another

    substring.

    Syntax:

    newstring = CHANGESTR(searchfor, string, exchange)

    string is the original string (to exchange substrings within).

    searchfor is which substring to search for (withinstring. Ifsearchforis anempty string, then no exchange is performed, and the original string is returned.

    exchange is the substring to insert in place ofsearchfor, whereversearchforoccurs withinstring. Ifexchange is an empty string, then each occurence of

    searchforis deleted without being replaced by anything.

    Returns

    A copy of the original string with all occurences ofsearchforreplaced with exchange.

    Notes

    The original string is not altered.

    Examples

    Example Used Output

    CHANGESTR('a', 'fred', 'c') 'fred'

    CHANGESTR('', '', 'new string') ''

    CHANGESTR('a', 'abcdef', 'x') 'xbcdef'

    CHANGESTR('0', '0', '1') '1'

    CHANGESTR('a', 'def', 'xyz') 'def'

    CHANGESTR('a', '', 'x') ''

    8

  • 8/3/2019 Tern Paper of Data

    9/28

    Operations on Strings 200

    8

    CHANGESTR('a', '', 'x') 'def'

    CHANGESTR('abc', 'abcdef', 'xyz') 'xyzdef'

    CHANGESTR('abcdefg', 'abcdef', 'xyz') 'abcdef'

    COMPARE

    Compares two strings for inequality, and returns the position where they differ.

    Syntax:

    result = COMPARE(string1, string2, padchar)

    string1 and string2 is the two strings to be compared. If one of the strings is shorter than the other,padcharis the character used to

    pad out the shorter string to the same length as the longer string. Ifpadcharisomitted, then by default, the shorter string is padded with extra spaces.

    Returns

    0 if both strings are equal. If not equal, then the first position where the two strings are

    different is returned (where 1 is the first character in the strings).

    Notes

    COMPARE() is case-sensitive, so 'BLORT' does not equal 'blort'. Use

    TRANSLATE() or the UPPER keyword to upper-case the strings prior to

    COMPARE(), if desired.

    Leading and trailing spaces do matter, so ' blort ' does not equal 'blort'. Use STRIP() to

    removed leading/trailing space prior to COMPARE(), if desired.

    Example

    Examples Used OutputCOMPARE('FooBar', 'Foobar') 4COMPARE('Foobar', 'Foobar') 0COMPARE('Foobarrr', 'Fooba') 6COMPARE('Foobarrr', 'Fooba', 'r') 0

    COPIES

    9

    http://www.ulisoft.org/rexx_referenz/funcs2.htm#TRANSLATEhttp://www.ulisoft.org/rexx_referenz/funcs2.htm#STRIPhttp://www.ulisoft.org/rexx_referenz/funcs2.htm#TRANSLATEhttp://www.ulisoft.org/rexx_referenz/funcs2.htm#STRIP
  • 8/3/2019 Tern Paper of Data

    10/28

    Operations on Strings 200

    8

    Creates a new string that is another string concatenated (ie,

    appended) a specified number of times.

    Syntax:

    newstring = COPIES(string, total)

    string is the original string (to append). Ifstringis an empty string, then theresulting newstring is also an empty string.

    total is a count of how many times to appendstring. totalcannot be negative,nor have a fractional component -- it must be a positive whole number. Iftotalis 0, an empty string is created.

    Returns

    The new string comprised oftotalinstances ofstringappended.

    Examples:

    Example Used Output

    COPIES('Foo', 3) 'FooFooFoo'

    COPIES('*', 16) '****************'

    COPIES('Bar ', 2) 'Bar Bar '

    COPIES('', 10000) ''

    COUNTSTR

    Counts how many occurences of a substring are within another string.

    Syntax:

    howmany = COUNTSTR(searchfor, string)

    string is the original string (to search forsearchforwithin).

    searchfor is which substring to search for withinstring. Ifsearchforis anempty string, then 0 is returned to indicate no occurrences ofsearchforwithin

    string.

    Returns

    10

  • 8/3/2019 Tern Paper of Data

    11/28

    Operations on Strings 200

    8

    A count of how many occurrences ofsearchforappear withinstring.

    Example

    Example Used OutputCOUNTSTR('', '') 0COUNTSTR('a', 'abcdef') 1COUNTSTR(0, 0) 1COUNTSTR('a', 'def') 0COUNTSTR('a', '') 0COUNTSTR('', 'def') 0COUNTSTR('abc', 'abcdef') 1COUNTSTR('abc', 'abcdef') 0COUNTSTR('abc', 'abcdefabccdabcd') 3

    COUNTSTR('aaa', 'aaaaaa') 2

    DELSTR

    Removes one or more characters from a string.

    Syntax:

    newstring = DELSTR(string, start, length)

    string is the string to remove characters from.

    start is which character number to start removing from, where 1 would be tostart removing at the first character in the string. If there are less characters in

    the string thanstart, then no characters are removed.

    length is the desired number of characters to remove (withinstring), startingat (ie, including) thestartcharacter. Iflength is omitted, then the default is to

    remove all character from thestartcharacter to the end of the string. lengthcannot be negative, nor have a fractional component -- it must be a positive

    whole number.

    Returns

    A copy of the original string without the removed characters.

    11

  • 8/3/2019 Tern Paper of Data

    12/28

    Operations on Strings 200

    8

    Notes

    It is not an error ifstartorlength (or a combination of them) refers to more charactersthan string actually contains.

    The original string is not altered. Only the returned value from DELSTR has

    characters removed.

    Example:

    Example Used Output

    DELSTR('Foobar', 3) 'Foo'

    DELSTR('Foobar', 3, 2) 'Foor'

    DELSTR('Foobar', 3, 4) 'Foo'

    DELSTR('Foobar', 7) 'Foobar'

    EXPAND

    Replaces tab characters with spaces, or vice versa.

    Syntax:

    newstring = EXPAND(string, options, tablewidth2, tablewidth2, )

    string is the string to replace characters within.

    options is the desired operation. It is one of the following:

    >Optio

    n Meaning

    'S' Replace each tab character with an appropriate number of spaces

    based upon the tabwidth args.

    'T' Replace space characters with a tab character based upon the

    tabwidth args.

    If omitted, options defaults to 'S'.

    tabwidth1 is the desired width of the first tab stop. For example, a value of'8' would put the first tab stop at the eighth character. If omitted, tabwidth1

    12

  • 8/3/2019 Tern Paper of Data

    13/28

    Operations on Strings 200

    8

    defaults to 8. There may be more tabwidth arguments supplied. For example, if

    tabwidth2 is supplied, then this sets the width of the second tab stop. For

    example, a value of '8' would effectively put the second tab stop at the sixteenth

    character. If there are more spaces/tabs to be replaced than there are tabwidths

    specified, then the value of the last tabwidth is used for all subsequentreplacements.

    Returns

    A copy of the original string with the space/tab characters replaced.

    Notes

    The first character instringis presumed to be at a tabstop.

    The original string is not altered. Only the returned value from EXPAND has

    characters replaced.

    Some interpreters do not support this function.

    Example:

    Example Used Output

    EXPAND(' Foo bar', 'T', 3) '09'X || 'Foo' || '09'X || 'bar'

    EXPAND(' Foo bar', 'T') ' Foo bar'

    EXPAND(' Foo bar', 'T', 3) ' Foo' || '09'X || ' bar'

    EXPAND(' Foo bar', 'T') '09'X || 'Foo bar'

    EXPAND(' Foo bar ', 'T', 3, 3, 6) '0909'X || ' Foo' || '09'X || ' bar '

    INSERT

    Inserts a substring into another string.

    Syntax:

    Newstring = INSERT(insert, string, position, length, padchar)

    insert is the substring to be inserted (intostring).

    string is the string into which insertis inserted.

    13

  • 8/3/2019 Tern Paper of Data

    14/28

    Operations on Strings 200

    8

    position is the desired character position (withinstring) after which to insertinsert. A position of 0 would cause insertto be inserted before the firstcharacter instring(ie, at the very start). A position of 1 would cause insertto

    be inserted after the first character instring(ie, at the very start). Ifposition is

    greater than the number of characters instring, then insertwill be inserted afterthe last character ofstring. Ifposition is omitted, then it defaults to 0.

    length is the desired length forinsert. Ifinsertis larger, then characters willbe deleted from the end of the string in order to fit the desired length. Ifinsert

    is smaller, then it is padded out withpadcharcharacters at the end to fit thedesired length. length must not be negative, nor have a fractional component --

    it must be a positive whole number. Iflength is omitted, then no truncation norpadding is performed upon insert.

    padchar is the character to use for padding (if the insertis not already >=

    length). Ifpadcharis omitted, the default is a space character.

    Returns

    A copy of the original string with insertinserted into it.

    Notes

    The original string is not altered. Only the returned value from INSERT has the

    inserted substring.

    Example:

    Example Used Output

    INSERT('first', 'SECOND') 'SECONDfirst'

    INSERT('first', 'SECOND', 3) 'fiSECONDrst'

    INSERT('first', 'SECOND', 3, 10) 'fiSECOND rst'

    INSERT('first', 'SECOND', 3, 10, *) 'fiSECOND****rst'

    INSERT('first', 'SECOND', 3, 4) 'fiSECOrst'

    INSERT('first', 'SECOND', 8) 'first SECOND'

    LASTPOS

    Finds the last occurrence of a substring within another string.

    14

  • 8/3/2019 Tern Paper of Data

    15/28

    Operations on Strings 200

    8

    Syntax:

    Where = LASTPOS(searchfor, string, start)

    searchfor is which substring to search for (withinstring. Ifsearchforis anempty string, then 0 is returned to indicate no occurrences ofsearchforwithin

    string.

    string is the original string (to search forsearchforwithin).

    start is which character position to start the backward search from, where 1would be to start searching backwards at the first character instring. If omitted,

    the default is to start searching from the last character.startmust not benegative, nor have a fractional component -- it must be a positive whole

    number.

    Returns

    Ifsearchforis found, then LASTPOS() returns the character position where the lastoccurrence ofsearchforoccurs withinstring(where 1 is the first character within

    string). Ifsearchforis not found, then LASTPOS() returns 0.

    Examples

    Example Used Output

    LASTPOS('be', 'to be or not to be') 17LASTPOS('be', 'to be or not to be', 10) 3LASTPOS('is', 'to be or not to be') 0

    LEFT

    Excerpts one or more characters from the left-hand side of a string.

    Syntax:

    excerpt = LEFT(string, length, padchar)

    string is the original string (from which to excerpt characters).

    length is the number of characters to be excerpted. Iflength is 0, nocharacters are excerpted. Iflength is greater than the number of characters in

    15

  • 8/3/2019 Tern Paper of Data

    16/28

    Operations on Strings 200

    8

    string, then the excerpt is padded out withpadcharcharacters to the desiredlength.

    padchar is the character to use for padding (if the original string is not >=length). Ifpadcharis omitted, the default is a space character.

    Returns

    A string containing the excerpted characters.

    Notes

    The original string is not altered.

    Example:

    Example Used Output

    LEFT('Foo bar', 5) 'Foo b'

    LEFT('Foo bar', 3) 'Foo'

    LEFT('Foo bar', 10) 'Foo bar '

    LEFT('Foo bar', 10, '*') 'Foo bar***'

    LENGTH

    Counts the number of characters in a string.

    Syntax:

    howmany = LENGTH(string)

    string is the string (whose length is to be calculated).

    Returns

    A count of how many characters are in the string.

    Notes

    Leading and trailing spaces are counted. You may wish to use STRIP first to trim

    those spaces.

    16

  • 8/3/2019 Tern Paper of Data

    17/28

    Operations on Strings 200

    8

    Example:

    Example Used Output

    LENGTH('') 0

    LENGTH('Foo') 3LENGTH(' Foo bar ') 7LENGTH(' foo bar ') 10

    OVERLAY

    Overlays a substring into another string. OVERLAY() differs from INSERT() in that

    OVERLAY() overwrites characters in the string.

    Syntax:

    newstring = OVERLAY(overlay, string, position, length, padchar)

    overlay is the substring to be inserted (intostring).

    string is the string into which overlay is overlaid.

    position is the desired character position (withinstring) at which to overlay overlay.A position of 1 would cause overlay to be overlaid at the first character instring(ie, atthe very start). Ifposition is greater than the number of characters instring, then the

    new string will be padded out withpadcharcharacters and then overlay will beinserted after those pad characters. Ifposition is omitted, then it defaults to 1.

    length is the desired length foroverlay. Ifoverlay is larger, then characters will bedeleted from the end in order to fit the desired length. Ifoverlay is smaller, then it is

    padded out withpadcharcharacters at the end to fit the desired length. length must

    not be negative, nor have a fractional component -- it must be a positive whole

    number. Iflength is omitted, then no truncation nor padding is performed upon

    overlay.

    padchar is the character to use for padding (if the overlay is not already >= length).Ifpadcharis omitted, the default is a space character.

    Returns

    17

  • 8/3/2019 Tern Paper of Data

    18/28

    Operations on Strings 200

    8

    A copy of the original string with overlay overlaid in it.

    Notes

    The original string is not altered. Only the returned value from OVERLAY has theoverlaid substring.

    Example Used Output

    OVERLAY('NEW', 'old-value') 'NEW-value'

    OVERLAY('NEW', 'old-value', 4) 'oldNEWlue'

    OVERLAY('NEW', 'old-value', 4, 5) 'oldNEW e'

    OVERLAY('NEW', 'old-value', 4, 5, *) 'oldNEW**e'

    OVERLAY('NEW', 'old-value', 4, 2) 'oldNEalue'

    OVERLAY('NEW', 'old-value', 8) 'old-valuNEW'

    OVERLAY('NEW', 'old-value', 11) 'old-value NEW'

    OVERLAY('NEW', 'old-value', 4, 2) 'oldNEalue'OVERLAY('NEW', 'old-value', 9) 'old-valuNEW'

    POS

    Finds the first occurrence of a substring within another string.

    Syntax:

    where = POS(searchfor, string, start)

    searchfor is which substring to search for (withinstring. Ifsearchforis anempty string, then 0 is returned to indicate no occurrences ofsearchforwithinstring.

    string is the original string (to search forsearchforwithin).

    start is which character position to start the search from, where 1 would be tostart searching at the first character instring. If omitted, the default is to startsearching from the first character.startmust not be negative, nor have a

    fractional component -- it must be a positive whole number.

    Returns

    Ifsearchforis found, then POS() returns the character position where the firstoccurrence ofsearchforoccurs withinstring(where 1 is the first character within

    string). Ifsearchforis not found, then POS() returns 0.

    18

  • 8/3/2019 Tern Paper of Data

    19/28

    Operations on Strings 200

    8

    Example:

    Example Used Output

    POS('be', 'to be or not to be') 4

    POS('to', 'to be or not to be',10) 17POS('to', 'to be or not to be',18) 0POS('is', 'to be or not to be') 0

    REVERSE

    Reverses the order of characters in a string.

    Syntax:

    newstring = REVERSE(string)

    string whose characters are to be reversed.

    Returns

    A copy of the original string with the order of its characters reversed.

    Notes

    The original string is not altered. Only the return value of REVERSE has its

    characters reversed.

    Example:

    Example Used Output

    REVERSE('FooBar') 'raBooF'

    REVERSE(' Foo Bar') 'raB ooF '

    REVERSE('3.14159') '95141.3'

    RIGHT

    Excerpts one or more characters from the right-hand side of a string.

    19

  • 8/3/2019 Tern Paper of Data

    20/28

    Operations on Strings 200

    8

    Syntax:

    excerpt = RIGHT(string, length, padchar)

    string is the original string (from which to excerpt characters). length is the number of characters to be excerpted. Iflength is 0, no characters

    are excerpted. Iflength is greater than the number of characters instring, thenthe excerpt is padded out on the left withpadcharcharacters to the desired

    length.

    padchar is the character to use for padding (if the original string is not >=length). Ifpadcharis omitted, the default is a space character.

    Returns

    A string containing the excerpted characters.

    Notes

    The original string is not altered.

    Examples

    Example Use Output

    RIGHT('Foo bar', 5) 'o bar'

    RIGHT('Foo bar', 4) ' bar'RIGHT('Foo bar', 10) ' Foo bar'

    STRIP

    Removes leading and/or trailing space (or other) characters from a string.

    Syntax:

    newstring = STRIP(string, option, padchar)

    string whose leading and trailing space characters are to be removed.

    padchar is the character to strip. Ifpadcharis omitted, the default is a spacecharacter.

    20

  • 8/3/2019 Tern Paper of Data

    21/28

    Operations on Strings 200

    8

    option determines whetherpadchars are stripped from the beginning and/orend ofstring. It must be one of the following:

    Optio

    n Meaning

    L (Leading) Only leading characters are stripped. Trailing

    characters are not.

    T (Trailing) Only trailing characters are stripped. Leading

    characters are not.

    B (Both) Both leading and trailing characters are stripped.

    If omitted, option defaults to 'B'.

    Returns

    A copy of the original string with its leading and trailing space characters removed.

    Notes

    The original string is not altered. Only the return value of STRIP has its

    leading/trailingpadchars removed.

    This removes only thosepadchars appearing at the front or end of the string. Todeletepadchars within the string, use SPACE().

    Whenpadcharis omitted, Reginald strips TAB characters as well as space characters.

    Other interpreters may strip only space characters (ie, not TAB).

    Example

    Example Used Output

    STRIP(' FooBar') 'FooBar'

    STRIP(' Foo Bar ') 'Foo Bar'STRIP(' Foo Bar ', 'L') 'Foo Bar '

    STRIP(' 3.14159 ') '3.14159'

    STRIP('*** Foo *** Bar ***', ,'*') ' Foo *** Bar'

    SUBSTR

    21

  • 8/3/2019 Tern Paper of Data

    22/28

    Operations on Strings 200

    8

    Excerpts one or more characters from a string, and returns that excerpt.

    Syntax:

    excerpt = SUBSTR(string, start, length, padchar)

    string is the original string (from which to excerpt characters).

    start is which character position to start the excerpt from, where 1 would be tostart the excerpt at the first character in the string. If there are less characters in

    the string thanstart, then an empty string is returned.startcannot be 0 ornegative, nor have a fractional component -- it must be a positive whole

    number.

    length is the number of characters to be excerpted, starting at the characterpositionstart. Iflength is omitted, the default is to excerpt all characters from

    startto the end of the string. Iflength is 0, no characters are excerpted. lengthcannot be negative, nor have a fractional component -- it must be a positive

    integer.

    padchar is the character to use for padding (if the original string is not >=length +start). Ifpadcharis omitted, the default is a space character.

    Returns

    A string containing the excerpted characters.

    Notes

    Any leading or trailing spaces are not trimmed from the excerpt.

    It is not an error ifstartorlength (or a combination of them) refers to more characters

    than string actually contains.

    The original string is not altered.

    Example

    Example Used Output

    SUBSTR('Foo bar', 3) 'o bar'

    SUBSTR('Foo bar', 3, 3) 'o b'

    SUBSTR('Foo bar', 4, 6) ' bar '

    SUBSTR('Foo bar', 4, 6, '*') ' bar**'

    SUBSTR('Foo bar', 9, 4, '*') '****'

    22

  • 8/3/2019 Tern Paper of Data

    23/28

    Operations on Strings 200

    8

    TRANSLATE

    Translates characters in a string to other characters, or makes a string uppercase.

    Syntax:

    newstring = TRANSLATE(string, tableout, tablein, padchar)

    string is the original string (to translate).

    tablein is a string containing upto 256 characters, representing characters that

    you wish translated to the respective characters in tableout. If one or both of the tables are specified, each character instringthat exists in

    tablein is translated to the character in tableoutthat occupies the same position asthe tablein character. Characters instringwhich are not found in tablein are left

    unchanged.

    If omitted, tablein defaults to all 256 characters of the computer's default

    character set. If omitted, tableoutdefaults to an empty set.Iftableoutis largerthan tablein, the extra entries are ignored.

    If smaller than tablein, tableoutis padded withpadcharcharacters to the samelength as tablein. Ifpadcharis omitted, the default padding is space characters.

    If both of the tables are omitted, TRANSLATE() upper-casesstring.

    If a character occurs more than once in tablein, only the first occurrence will

    matter.

    Returns

    A copy of the original string with each tablein character translated to its respective

    tableout's character.

    Notes

    The original string is not altered. Only the return value of TRANSLATE has its

    characters translated.

    Some REXX interpreters support the UPPER keyword which can be used to translate

    the value of a variable.

    /* Upper-case My_Variable's value. */

    UPPER My_Variable

    23

  • 8/3/2019 Tern Paper of Data

    24/28

    Operations on Strings 200

    8

    You can also specify a variable whose value is the name of the

    variables whose values you wish upper-cased. You put that

    variable's name in parentheses.

    /* Upper-case My_Variable's and Something.1's values. */these = 'My_Variable Something.1'

    UPPER (these)

    Examples

    Examples Used Output

    TRANSLATE('FooBar') 'FOOBAR'

    TRANSLATE('FooBar', 'ABFORabfor',

    'abforABFOR')

    'fOObAR'

    TRANSLATE('FooBar', 'abfor') 'F B 'TRANSLATE('FooBar', 'abfor', , '#') 'F##B##'

    VERIFY

    Tests if any characters of one string also occur in another string.

    Syntax:

    Where = VERFY(string, Lookfor, option, start)

    string is the string to search (forlookfor).

    start is which character number to start searching from, where 1 would be tostart searching at the first character in the string. If there are less characters in

    the string thanstart, then a 0 is returned to indicate that no characters in lookformatched.

    option must be one of:

    Optio

    n Meaning

    N (Nomatch) Return the position of the first character in string that isn't

    found in lookfor, or 0 if all of the characters in string also exist in

    24

  • 8/3/2019 Tern Paper of Data

    25/28

    Operations on Strings 200

    8

    lookfor.

    M

    (Match) Return the position of the first character in string that also

    exists in lookfor, or 0 none of the characters in string also exist in

    lookfor.

    If omitted, option defaults to 'N'.

    Returns

    A character position (where 1 is the first character instring).

    Notes

    It is not an error ifstartrefers to more characters than string actually contains.

    Example:

    Example Used Output

    VERIFY('foobar', 'barfo') 2VERIFY('foobar', 'barfo', 'M') 2VERIFY('foobar', 'fob', 'N') 5VERIFY('foobar', 'barf', 'N', 3) 3VERIFY('foobar', 'barf', 'N', 4) 0

    XRANGE

    Creates a range of characters between a given start character and end character. The

    range of characters is produced from the computer's character set.

    Syntax:

    newstring = XRANGE(start, end)

    start is which character to start from. If omitted, the default is to start fromcharacter 0 ('00'x).

    25

  • 8/3/2019 Tern Paper of Data

    26/28

    Operations on Strings 200

    8

    end is which character to end at. If omitted, the default is to end at character255 ('ff'x).

    Returns

    A string that consists of all the characters fromstartthrough end, inclusive.

    Notes

    The actual representation of the output from XRANGE() depends on the character set

    used by your computer.

    If the value ofstartis larger than the value ofend, the output will wrap around fromffx to 00x. Ifstartorendis not a string containing exactly one character, this raises

    a SYNTAX error.

    Example:

    Example Used Output

    XRANGE('A', 'J') 'ABCDEFGHIJ'

    XRANGE('FC'x) 'FCFDFEFF'x

    XRANGE(, '05'x) '000102030405'x

    XRANGE('FD'x, '04'x) 'FDFEFF0001020304'x

    26

  • 8/3/2019 Tern Paper of Data

    27/28

    Operations on Strings 200

    8

    ConclusionAstringis basically a sequence of characters that can be indexed. Thestringdatatype provides a

    number of useful and powerful high level operations. All the operations of strings are discussed

    above, all the syntax and examples helps us to understand the concept of operations on strings.

    27

  • 8/3/2019 Tern Paper of Data

    28/28

    Operations on Strings 200

    8

    References

    www.cs.grinnell.edu/~rebelsky/Espresso/Readings/strings.html

    www.cs.hmc.edu/~geoff/classes/hmc.cs070.200401/notes/strings.html

    www.ezysoftware.com/ezyprolog/Prolog_Inference_Engine/Prolog.../String_o

    perations/psp_cat_String_Operations.htm

    http://www.cs.hmc.edu/~geoff/classes/hmc.cs070.200401/notes/strings.htmlhttp://www.cs.hmc.edu/~geoff/classes/hmc.cs070.200401/notes/strings.html