Cover V06, I12
Article
Listing 1
Listing 2

dec97.tar


Listing 2: stringlib.java -String class for the vGen byte code

// vgen-  The web version generator
// Copyright (c) 1997 by James L. Pinson
// look to http://www.polaris.net/~jpinson/home/vgen.html for info on the
// latest version.


import java.io.*;
import java.util.*;

public class stringlib
{
static String string="";
static  char[] chararray1= new char[200];
static char[] chararray2= new char [200];
static String leftstring="";
static String rightstring="";




// this breaks a string into a left and right section (internal use only)
private static void SplitOnString (String original, String target)
{
// insure leftsring and rightstring are null
leftstring=""; rightstring="";
int begin= original.indexOf (target);
if ( begin < 0 ) return;
leftstring= original.substring (0,begin);
rightstring=original.substring (begin+target.length(), original.length());
}

// returns the string to the right side of a character
public static String GetRightValue(String original, char letter){
int pos =original.indexOf( letter);
if (pos==-1) return (""); // no char found
if (pos==original.length()-1) return (""); //nothing to right of char
pos++;
return (original.substring(pos) );
}


// returns the string to the left side of a character

public static String GetLeftValue(String original, char letter){


int pos =original.indexOf( letter);
if (pos==0) return (""); // no value to left
if (pos==-1) return ("");// char not found
return (original.substring(0,pos) );
}

public static String ReplaceFirst(String original, String oldstring, String newstring){
int start =original.indexOf(oldstring);
String tempstring="";
stringlib.SplitOnString(original, oldstring);
tempstring=leftstring;
tempstring=tempstring.concat(newstring);
tempstring=tempstring.concat(rightstring);
return(tempstring);
}

//forces the last letter of a string to be specified letter
public static String forcelastchar(String original, char letter){
int length;
length= original.length();

if ( original.charAt(original.length()-1)== letter)
return (original);  // no change needed
else
original=original + letter;
return (original );
}

} // end of stringlib