{"id":23188,"date":"2013-05-13T17:01:55","date_gmt":"2013-05-13T11:31:55","guid":{"rendered":"http:\/\/vskills.in\/certification\/tutorial\/?p=23188"},"modified":"2024-04-12T14:23:51","modified_gmt":"2024-04-12T08:53:51","slug":"number-and-string-manipulation","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/","title":{"rendered":"Number and String manipulation"},"content":{"rendered":"<p>XSLT is a language for manipulating XML documents, and XML documents are text. When you&#8217;re manipulating text, functions for searching strings and pulling out substrings are indispensable for rearranging documents to create new documents. The XPath string functions incorporated by XSLT give you a lot of power when you&#8217;re manipulating element character data, attribute values, and any other strings of text that your stylesheet can access. We&#8217;ll start by looking at ways to use these functions to split up strings and how a PCDATA element might be split into subelements.<\/p>\n<p>Bash supports a surprising number of string manipulation operations. Unfortunately, these tools lack a unified focus. Some are a subset of\u00a0parameter substitution, and others fall under the functionality of the UNIX\u00a0expr\u00a0command. This results in inconsistent command syntax and overlap of functionality, not to mention confusion.<\/p>\n<div>\n<p><b>String Length<\/b><\/p>\n<dl>\n<dt>${#string}<\/dt>\n<dt>expr length $string<\/dt>\n<dd>These are the equivalent of\u00a0<i>strlen()<\/i>\u00a0in\u00a0<i>C<\/i>.<\/dd>\n<dt>expr &#8220;$string&#8221; : &#8216;.*&#8217;<\/dt>\n<dd>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n\necho ${#stringZ}                 # 15\necho `expr length $stringZ`      # 15\necho `expr \"$stringZ\" : '.*'`    # 15<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<\/dl>\n<\/div>\n<div>\n<p><b>Example 10-1. Inserting a blank line between paragraphs in a text file<\/b><\/p>\n<table border=\"0\" width=\"100%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>#!\/bin\/bash\n# paragraph-space.sh\n# Ver. 2.1, Reldate 29Jul12 [fixup]\n\n# Inserts a blank line between paragraphs of a single-spaced text file.\n# Usage: $0 &lt;FILENAME\n\nMINLEN=60        # Change this value? It's a judgment call.\n#  Assume lines shorter than $MINLEN characters ending in a period\n#+ terminate a paragraph. See exercises below.\n\nwhile read line  # For as many lines as the input file has ...\ndo\n  echo \"$line\"   # Output the line itself.\n\n  len=${#line}\n  if [[ \"$len\" -lt \"$MINLEN\" &amp;&amp; \"$line\" =~ [*{\\.}]$ ]]\n# if [[ \"$len\" -lt \"$MINLEN\" &amp;&amp; \"$line\" =~ \\[*\\.\\] ]]\n# An update to Bash broke the previous version of this script. Ouch!\n# Thank you, Halim Srama, for pointing this out and suggesting a fix.\n    then echo    #  Add a blank line immediately\n  fi             #+ after a short line terminated by a period.\ndone\n\nexit\n\n# Exercises:\n# ---------\n#  1) The script usually inserts a blank line at the end\n#+    of the target file. Fix this.\n#  2) Line 17 only considers periods as sentence terminators.\n#     Modify this to include other common end-of-sentence characters,\n#+    such as ?, !, and \".<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<p><b>Length of Matching Substring at Beginning of String<\/b><\/p>\n<dl>\n<dt>expr match &#8220;$string&#8221; &#8216;$substring&#8217;<\/dt>\n<dd><tt><i>$substring<\/i><\/tt>\u00a0is a\u00a0regular expression.<\/dd>\n<dt>expr &#8220;$string&#8221; : &#8216;$substring&#8217;<\/dt>\n<dd><tt><i>$substring<\/i><\/tt>\u00a0is a regular expression.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#       |------|\n#       12345678\n\necho `expr match \"$stringZ\" 'abc[A-Z]*.2'`   # 8\necho `expr \"$stringZ\" : 'abc[A-Z]*.2'`       # 8<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<\/dl>\n<\/div>\n<div>\n<p><b>Index<\/b><\/p>\n<dl>\n<dt>expr index $string $substring<\/dt>\n<dd>Numerical position in $string of first character in $substring that matches.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#       123456 ...\necho `expr index \"$stringZ\" C12`             # 6\n                                             # C position.\n\necho `expr index \"$stringZ\" 1c`              # 3\n# 'c' (in #3 position) matches before '1'.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This is the near equivalent of\u00a0<i>strchr()<\/i>\u00a0in\u00a0<i>C<\/i>.<\/dd>\n<\/dl>\n<\/div>\n<div>\n<p><b>Substring Extraction<\/b><\/p>\n<dl>\n<dt>${string:position}<\/dt>\n<dd>Extracts substring from\u00a0<tt><i>$string<\/i><\/tt>\u00a0at\u00a0<tt><i>$position<\/i><\/tt>.If the\u00a0<tt>$string<\/tt>\u00a0parameter is\u00a0&#8220;*&#8221;\u00a0or\u00a0&#8220;@&#8221;, then this extracts the\u00a0positional parameters,\u00a0[1]\u00a0starting at\u00a0<tt>$position<\/tt>.<\/dd>\n<dt>${string:position:length}<\/dt>\n<dd>Extracts\u00a0<tt><i>$length<\/i><\/tt>\u00a0characters of substring from\u00a0<tt><i>$string<\/i><\/tt>\u00a0at\u00a0<tt><i>$position<\/i><\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#       0123456789.....\n#       0-based indexing.\n\necho ${stringZ:0}                            # abcABC123ABCabc\necho ${stringZ:1}                            # bcABC123ABCabc\necho ${stringZ:7}                            # 23ABCabc\n\necho ${stringZ:7:3}                          # 23A\n                                             # Three characters of substring.\n\n# Is it possible to index from the right end of the string?\n\necho ${stringZ:-4}                           # abcABC123ABCabc\n# Defaults to full string, as in ${parameter:-default}.\n# However . . .\n\necho ${stringZ:(-4)}                         # Cabc \necho ${stringZ: -4}                          # Cabc\n# Now, it works.\n# Parentheses or added space \"escape\" the position parameter.\n\n# Thank you, Dan Jacobson, for pointing this out.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The\u00a0<i>position<\/i>\u00a0and\u00a0<i>length<\/i>\u00a0arguments can be\u00a0&#8220;parameterized,&#8221;\u00a0that is, represented as a variable, rather than as a numerical constant.<\/p>\n<div>\n<p><b>Example 10-2. Generating an 8-character\u00a0&#8220;random&#8221;\u00a0string<\/b><\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>#!\/bin\/bash\n# rand-string.sh\n# Generating an 8-character \"random\" string.\n\nif [ -n \"$1\" ]  #  If command-line argument present,\nthen            #+ then set start-string to it.\n  str0=\"$1\"\nelse            #  Else use PID of script as start-string.\n  str0=\"$\"\nfi\n\nPOS=2  # Starting from position 2 in the string.\nLEN=8  # Extract eight characters.\n\nstr1=$( echo \"$str0\" | md5sum | md5sum )\n#  Doubly scramble     ^^^^^^   ^^^^^^\n#+ by piping and repiping to md5sum.\n\nrandstring=\"${str1:$POS:$LEN}\"\n# Can parameterize ^^^^ ^^^^\n\necho \"$randstring\"\n\nexit $?\n\n# bozo$ .\/rand-string.sh my-password\n# 1bdd88c4\n\n#  No, this is is not recommended\n#+ as a method of generating hack-proof passwords.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>If the\u00a0<tt>$string<\/tt>\u00a0parameter is\u00a0&#8220;*&#8221;\u00a0or\u00a0&#8220;@&#8221;, then this extracts a maximum of\u00a0<tt>$length<\/tt>\u00a0positional parameters, starting at\u00a0<tt>$position<\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>echo ${*:2}          # Echoes second and following positional parameters.\necho ${@:2}          # Same as above.\n\necho ${*:2:3}        # Echoes three positional parameters, starting at second.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<dt>expr substr $string $position $length<\/dt>\n<dd>Extracts\u00a0<tt><i>$length<\/i><\/tt>\u00a0characters from\u00a0<tt><i>$string<\/i><\/tt>\u00a0starting at\u00a0<tt><i>$position<\/i><\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#       123456789......\n#       1-based indexing.\n\necho `expr substr $stringZ 1 2`              # ab\necho `expr substr $stringZ 4 3`              # ABC<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<dt>expr match &#8220;$string&#8221; &#8216;\\($substring\\)&#8217;<\/dt>\n<dd>Extracts\u00a0<tt><i>$substring<\/i><\/tt>\u00a0at beginning of\u00a0<tt><i>$string<\/i><\/tt>, where\u00a0<tt><i>$substring<\/i><\/tt>\u00a0is a\u00a0regular expression.<\/dd>\n<dt>expr &#8220;$string&#8221; : &#8216;\\($substring\\)&#8217;<\/dt>\n<dd>Extracts\u00a0<tt><i>$substring<\/i><\/tt>\u00a0at beginning of\u00a0<tt><i>$string<\/i><\/tt>, where\u00a0<tt><i>$substring<\/i><\/tt>\u00a0is a regular expression.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#       =======\t    \n\necho `expr match \"$stringZ\" '\\(.[b-c]*[A-Z]..[0-9]\\)'`   # abcABC1\necho `expr \"$stringZ\" : '\\(.[b-c]*[A-Z]..[0-9]\\)'`       # abcABC1\necho `expr \"$stringZ\" : '\\(.......\\)'`                   # abcABC1\n# All of the above forms give an identical result.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<dt>expr match &#8220;$string&#8221; &#8216;.*\\($substring\\)&#8217;<\/dt>\n<dd>Extracts\u00a0<tt><i>$substring<\/i><\/tt>\u00a0at\u00a0<em>end<\/em>\u00a0of\u00a0<tt><i>$string<\/i><\/tt>, where\u00a0<tt><i>$substring<\/i><\/tt>\u00a0is a regular expression.<\/dd>\n<dt>expr &#8220;$string&#8221; : &#8216;.*\\($substring\\)&#8217;<\/dt>\n<dd>Extracts\u00a0<tt><i>$substring<\/i><\/tt>\u00a0at\u00a0<em>end<\/em>\u00a0of\u00a0<tt><i>$string<\/i><\/tt>, where\u00a0<tt><i>$substring<\/i><\/tt>\u00a0is a regular expression.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#                ======\n\necho `expr match \"$stringZ\" '.*\\([A-C][A-C][A-C][a-c]*\\)'`    # ABCabc\necho `expr \"$stringZ\" : '.*\\(......\\)'`                       # ABCabc<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<\/dl>\n<\/div>\n<div>\n<p><b>Substring Removal<\/b><\/p>\n<dl>\n<dt>${string#substring}<\/dt>\n<dd>Deletes shortest match of\u00a0<tt><i>$substring<\/i><\/tt>\u00a0from\u00a0<em>front<\/em>\u00a0of\u00a0<tt><i>$string<\/i><\/tt>.<\/dd>\n<dt>${string##substring}<\/dt>\n<dd>Deletes longest match of\u00a0<tt><i>$substring<\/i><\/tt>\u00a0from\u00a0<em>front<\/em>\u00a0of\u00a0<tt><i>$string<\/i><\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#       |----|          shortest\n#       |----------|    longest\n\necho ${stringZ#a*C}      # 123ABCabc\n# Strip out shortest match between 'a' and 'C'.\n\necho ${stringZ##a*C}     # abc\n# Strip out longest match between 'a' and 'C'.\n\n# You can parameterize the substrings.\n\nX='a*C'\n\necho ${stringZ#$X}      # 123ABCabc\necho ${stringZ##$X}     # abc\n                        # As above.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<dt>${string%substring}<\/dt>\n<dd>Deletes shortest match of\u00a0<tt><i>$substring<\/i><\/tt>\u00a0from\u00a0<em>back<\/em>\u00a0of\u00a0<tt><i>$string<\/i><\/tt>.For example:<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre># Rename all filenames in $PWD with \"TXT\" suffix to a \"txt\" suffix.\n# For example, \"file1.TXT\" becomes \"file1.txt\" . . .\n\nSUFF=TXT\nsuff=txt\n\nfor i in $(ls *.$SUFF)\ndo\n  mv -f $i ${i%.$SUFF}.$suff\n  #  Leave unchanged everything *except* the shortest pattern match\n  #+ starting from the right-hand-side of the variable $i . . .\ndone ### This could be condensed into a \"one-liner\" if desired.\n\n# Thank you, Rory Winston.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<dt>${string%%substring}<\/dt>\n<dd>Deletes longest match of\u00a0<tt><i>$substring<\/i><\/tt>\u00a0from\u00a0<em>back<\/em>\u00a0of\u00a0<tt><i>$string<\/i><\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n#                    ||     shortest\n#        |------------|     longest\n\necho ${stringZ%b*c}      # abcABC123ABCa\n# Strip out shortest match between 'b' and 'c', from back of $stringZ.\n\necho ${stringZ%%b*c}     # a\n# Strip out longest match between 'b' and 'c', from back of $stringZ.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This operator is useful for generating filenames.<\/p>\n<div>\n<p><b>Example 10-3. Converting graphic file formats, with filename change<\/b><\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>#!\/bin\/bash\n#  cvt.sh:\n#  Converts all the MacPaint image files in a directory to \"pbm\" format.\n\n#  Uses the \"macptopbm\" binary from the \"netpbm\" package,\n#+ which is maintained by Brian Henderson (bryanh@giraffe-data.com).\n#  Netpbm is a standard part of most Linux distros.\n\nOPERATION=macptopbm\nSUFFIX=pbm          # New filename suffix. \n\nif [ -n \"$1\" ]\nthen\n  directory=$1      # If directory name given as a script argument...\nelse\n  directory=$PWD    # Otherwise use current working directory.\nfi  \n\n#  Assumes all files in the target directory are MacPaint image files,\n#+ with a \".mac\" filename suffix.\n\nfor file in $directory\/*    # Filename globbing.\ndo\n  filename=${file%.*c}      #  Strip \".mac\" suffix off filename\n                            #+ ('.*c' matches everything\n\t\t\t    #+ between '.' and 'c', inclusive).\n  $OPERATION $file &gt; \"$filename.$SUFFIX\"\n                            # Redirect conversion to new filename.\n  rm -f $file               # Delete original files after converting.   \n  echo \"$filename.$SUFFIX\"  # Log what is happening to stdout.\ndone\n\nexit 0\n\n# Exercise:\n# --------\n#  As it stands, this script converts *all* the files in the current\n#+ working directory.\n#  Modify it to work *only* on files with a \".mac\" suffix.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<p><b>Example 10-4. Converting streaming audio files to\u00a0<i>ogg<\/i><\/b><\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>#!\/bin\/bash\n# ra2ogg.sh: Convert streaming audio files (*.ra) to ogg.\n\n# Uses the \"mplayer\" media player program:\n#      http:\/\/www.mplayerhq.hu\/homepage\n# Uses the \"ogg\" library and \"oggenc\":\n#      http:\/\/www.xiph.org\/\n#\n# This script may need appropriate codecs installed, such as sipr.so ...\n# Possibly also the compat-libstdc++ package.\n\nOFILEPREF=${1%%ra}      # Strip off the \"ra\" suffix.\nOFILESUFF=wav           # Suffix for wav file.\nOUTFILE=\"$OFILEPREF\"\"$OFILESUFF\"\nE_NOARGS=85\n\nif [ -z \"$1\" ]          # Must specify a filename to convert.\nthen\n  echo \"Usage: `basename $0` [filename]\"\n  exit $E_NOARGS\nfi\n\n##########################################################################\nmplayer \"$1\" -ao pcm:file=$OUTFILE\noggenc \"$OUTFILE\"  # Correct file extension automatically added by oggenc.\n##########################################################################\n\nrm \"$OUTFILE\"      # Delete intermediate *.wav file.\n                   # If you want to keep it, comment out above line.\n\nexit $?\n\n#  Note:\n#  ----\n#  On a Website, simply clicking on a *.ram streaming audio file\n#+ usually only downloads the URL of the actual *.ra audio file.\n#  You can then use \"wget\" or something similar\n#+ to download the *.ra file itself.\n\n#  Exercises:\n#  ---------\n#  As is, this script converts only *.ra filenames.\n#  Add flexibility by permitting use of *.ram and other filenames.\n#\n#  If you're really ambitious, expand the script\n#+ to do automatic downloads and conversions of streaming audio files.\n#  Given a URL, batch download streaming audio files (using \"wget\")\n#+ and convert them on the fly.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>A simple emulation of\u00a0getopt\u00a0using substring-extraction constructs.<\/p>\n<div>\n<p><b>Example 10-5. Emulating\u00a0<i>getopt<\/i><\/b><\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>#!\/bin\/bash\n# getopt-simple.sh\n# Author: Chris Morgan\n# Used in the ABS Guide with permission.\n\ngetopt_simple()\n{\n    echo \"getopt_simple()\"\n    echo \"Parameters are '$*'\"\n    until [ -z \"$1\" ]\n    do\n      echo \"Processing parameter of: '$1'\"\n      if [ ${1:0:1} = '\/' ]\n      then\n          tmp=${1:1}               # Strip off leading '\/' . . .\n          parameter=${tmp%%=*}     # Extract name.\n          value=${tmp##*=}         # Extract value.\n          echo \"Parameter: '$parameter', value: '$value'\"\n          eval $parameter=$value\n      fi\n      shift\n    done\n}\n\n# Pass all options to getopt_simple().\ngetopt_simple $*\n\necho \"test is '$test'\"\necho \"test2 is '$test2'\"\n\nexit 0  # See also, UseGetOpt.sh, a modified version of this script.\n\n---\n\nsh getopt_example.sh \/test=value1 \/test2=value2\n\nParameters are '\/test=value1 \/test2=value2'\nProcessing parameter of: '\/test=value1'\nParameter: 'test', value: 'value1'\nProcessing parameter of: '\/test2=value2'\nParameter: 'test2', value: 'value2'\ntest is 'value1'\ntest2 is 'value2'<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/dd>\n<\/dl>\n<\/div>\n<div>\n<p><b>Substring Replacement<\/b><\/p>\n<dl>\n<dt>${string\/substring\/replacement}<\/dt>\n<dd>Replace first\u00a0<i>match<\/i>\u00a0of\u00a0<tt><i>$substring<\/i><\/tt>\u00a0with\u00a0<tt><i>$replacement<\/i><\/tt>.\u00a0[2]<\/dd>\n<dt>${string\/\/substring\/replacement}<\/dt>\n<dd>Replace all matches of\u00a0<tt><i>$substring<\/i><\/tt>\u00a0with\u00a0<tt><i>$replacement<\/i><\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n\necho ${stringZ\/abc\/xyz}       # xyzABC123ABCabc\n                              # Replaces first match of 'abc' with 'xyz'.\n\necho ${stringZ\/\/abc\/xyz}      # xyzABC123ABCxyz\n                              # Replaces all matches of 'abc' with # 'xyz'.\n\necho  ---------------\necho \"$stringZ\"               # abcABC123ABCabc\necho  ---------------\n                              # The string itself is not altered!\n\n# Can the match and replacement strings be parameterized?\nmatch=abc\nrepl=000\necho ${stringZ\/$match\/$repl}  # 000ABC123ABCabc\n#              ^      ^         ^^^\necho ${stringZ\/\/$match\/$repl} # 000ABC123ABC000\n# Yes!          ^      ^        ^^^         ^^^\n\necho\n\n# What happens if no $replacement string is supplied?\necho ${stringZ\/abc}           # ABC123ABCabc\necho ${stringZ\/\/abc}          # ABC123ABC\n# A simple deletion takes place.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/dd>\n<dt>${string\/#substring\/replacement}<\/dt>\n<dd>If\u00a0<tt><i>$substring<\/i><\/tt>\u00a0matches\u00a0<em>front<\/em>\u00a0end of\u00a0<tt><i>$string<\/i><\/tt>, substitute\u00a0<tt><i>$replacement<\/i><\/tt>\u00a0for\u00a0<tt><i>$substring<\/i><\/tt>.<\/dd>\n<dt>${string\/%substring\/replacement}<\/dt>\n<dd>If\u00a0<tt><i>$substring<\/i><\/tt>\u00a0matches\u00a0<em>back<\/em>\u00a0end of\u00a0<tt><i>$string<\/i><\/tt>, substitute\u00a0<tt><i>$replacement<\/i><\/tt>\u00a0for\u00a0<tt><i>$substring<\/i><\/tt>.<\/p>\n<table border=\"0\" width=\"90%\" bgcolor=\"#E0E0E0\">\n<tbody>\n<tr>\n<td>\n<pre>stringZ=abcABC123ABCabc\n\necho ${stringZ\/#abc\/XYZ}          # XYZABC123ABCabc\n                                  # Replaces front-end match of 'abc' with 'XYZ'.\n\necho ${stringZ\/%abc\/XYZ}          # abcABC123ABCXYZ\n                                  # Replaces back-end match of 'abc' with 'XYZ'.<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"apply\">\n<h5>Go to- <a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/xml-developer\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Certified XML Developer Tutorial<\/strong><\/a><\/h5>\n<\/div>\n<\/dd>\n<\/dl>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>XSLT is a language for manipulating XML documents, and XML documents are text. When you&#8217;re manipulating text, functions for searching strings and pulling out substrings are indispensable for rearranging documents to create new documents. The XPath string functions incorporated by XSLT give you a lot of power when you&#8217;re manipulating element character data, attribute values,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[3353],"tags":[4568,4567,4569],"class_list":["post-23188","page","type-page","status-publish","hentry","category-xml","tag-number-and-string","tag-number-and-string-manipulation","tag-string-manipulation"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Number and String manipulation - Tutorial<\/title>\n<meta name=\"description\" content=\"Number and String manipulation\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Number and String manipulation - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Number and String manipulation\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:53:51+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/\",\"name\":\"Number and String manipulation - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2013-05-13T11:31:55+00:00\",\"dateModified\":\"2024-04-12T08:53:51+00:00\",\"description\":\"Number and String manipulation\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Number and String manipulation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Number and String manipulation - Tutorial","description":"Number and String manipulation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/","og_locale":"en_US","og_type":"article","og_title":"Number and String manipulation - Tutorial","og_description":"Number and String manipulation","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:53:51+00:00","twitter_misc":{"Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/","name":"Number and String manipulation - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2013-05-13T11:31:55+00:00","dateModified":"2024-04-12T08:53:51+00:00","description":"Number and String manipulation","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/number-and-string-manipulation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Number and String manipulation"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/23188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=23188"}],"version-history":[{"count":4,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/23188\/revisions"}],"predecessor-version":[{"id":134054,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/23188\/revisions\/134054"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=23188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=23188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=23188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}