public static class SAFSPlus.Strings
extends java.lang.Object
If you meet some errors when calling these API, please try to run
SAFSPlus.DriverCommand.Expressions(boolean)
to turn off the expression as
Misc.Expressions(false);
and then call the string method
Strings.xxx();
Constructor and Description |
---|
Strings() |
Modifier and Type | Method and Description |
---|---|
static boolean |
CleanString(java.lang.String source,
java.lang.String resultVar)
For each char in string: if ((char .gt.
|
static boolean |
Compare(java.lang.String source,
java.lang.String destination,
java.lang.String resultVar)
Compares two strings.
|
static boolean |
Compare(java.lang.String source,
java.lang.String destination,
java.lang.String resultVar,
boolean regexMatch)
Compares a string with a normal string or a regular expression.
|
static boolean |
Concatenate(java.lang.String str1,
java.lang.String str2,
java.lang.String resultVar)
Concatenate String1 with String2 and returns concatenated string.
|
static boolean |
GetField(java.lang.String source,
int index,
java.lang.String delimiters,
java.lang.String resultVar)
Get a field out of a string using specified delimiter(s).
|
static boolean |
GetFieldCount(java.lang.String source,
int index,
java.lang.String delimiters,
java.lang.String resultVar)
Finds the count of all fields within the string found from startindex to the end of the string.
|
static boolean |
GetFixedWidthField(java.lang.String source,
int fieldID,
int fixedWidth,
java.lang.String resultVar)
Given an Input of fixed-width fields, return the nth(FieldID) Field in the record.
|
static boolean |
GetMultiDelimitedField(java.lang.String source,
int fieldID,
int startIndex,
java.lang.String delimiters,
java.lang.String resultVar)
Given a sourceString of delimited fields, return the nth(FieldID) Field in the record from startIndex.
|
static boolean |
GetMultiDelimitedFieldCount(java.lang.String source,
int startIndex,
java.lang.String delimiters,
java.lang.String resultVar)
Finds the count of all fields within the input string found from start-index to the end of the inputRecord.
|
static boolean |
GetNextDelimiterIndex(java.lang.String source,
int startIndex,
java.lang.String delimiters,
java.lang.String resultVar)
Finds the index of the first character matching one of the provided delimiter characters.
|
static boolean |
GetREDelimitedField(java.lang.String source,
int index,
java.lang.String regexDelimiters,
java.lang.String resultVar)
Returns the requested field contained in the input string using the passed in regular expression as the delimiter(s).
|
static boolean |
GetREDelimitedFieldCount(java.lang.String source,
int startIndex,
java.lang.String regexDelimiters,
java.lang.String resultVar)
Get the number of fields contained in the input string using the passed in regular expression as the delimiter(s).
|
static boolean |
GetSubstringsInString(java.lang.String source,
java.lang.String regexStart,
java.lang.String regexStop,
java.lang.String resultVar)
Extract dynamic substring from a string using regular expressions.
|
static boolean |
GetSystemEnviron(java.lang.String systemVariable,
java.lang.String resultVar)
Get a system environment variable value.
|
static boolean |
GetSystemUser(java.lang.String resultVar)
Get the USERID of the currently logged on user as stored in System Environment variables.
|
static boolean |
GetTrimmedField(java.lang.String source,
int index,
java.lang.String delimiters,
java.lang.String resultVar)
Get a trimmed field out of a string using specified delimiter(s).
|
static boolean |
Index(int startIndex,
java.lang.String source,
java.lang.String findString,
java.lang.String resultVar)
Returns the position of the first occurrence of one string within another string.
|
static boolean |
Left(java.lang.String source,
int length,
java.lang.String resultVar)
Returns a string of a specified number of characters copied from the beginning of another string.
|
static boolean |
LeftTrim(java.lang.String source,
java.lang.String resultVar)
A new string trimmed of leading tabs and spaces.
|
static boolean |
Length(java.lang.String source,
java.lang.String resultVar)
Returns the length of a string or variable.
|
static boolean |
Replace(java.lang.String source,
java.lang.String find,
java.lang.String replace,
java.lang.String resultVar)
Replace 'find' substring with 'replace' substring.
|
static boolean |
Right(java.lang.String source,
int length,
java.lang.String resultVar)
Returns a string of a specified number of characters copied from the end of another string.
|
static boolean |
RightTrim(java.lang.String source,
java.lang.String resultVar)
A new string trimmed of ending tabs and spaces.
|
static boolean |
SubString(java.lang.String source,
int start,
int length,
java.lang.String resultVar)
The substring to retrieve starts at the specified start character index and ends after
the specified number of characters have been copied. |
static boolean |
ToLowerCase(java.lang.String source,
java.lang.String resultVar)
Returns a copy of a string, with all letters converted to lowercase.
|
static boolean |
ToUpperCase(java.lang.String source,
java.lang.String resultVar)
Returns a copy of a string, with all letters converted to uppercase.
|
static boolean |
Trim(java.lang.String source,
java.lang.String resultVar)
Returns a new string trimmed of leading and trailing tabs and spaces.
|
public static boolean CleanString(java.lang.String source, java.lang.String resultVar)
source
- String, (could come from a ^variable).resultVar
- String, the variable to hold the result of the operationSAFSPlus.prevResults
,
TestRecordData.getStatusCode()
,
String var = "result";
String controlA = "";
String content = "ab"+controlA+"cd\n";
if(Strings.CleanString(content, var))
System.out.println("CleanString '"+content+"' success: result is "+GetVariableValue(var));//expected result 'abcd '
public static boolean Compare(java.lang.String source, java.lang.String destination, java.lang.String resultVar)
source
- String, string to comparedestination
- String, string to compareresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "hello";
String destination = "Hello";
if(Strings.Compare(source, destination, var))
System.out.println("Compare success: result is "+GetVariableValue(var));//expected result 'false'
public static boolean Compare(java.lang.String source, java.lang.String destination, java.lang.String resultVar, boolean regexMatch)
source
- String, string to comparedestination
- String, normal string to compare or the regex string to matchresultVar
- String, the variable to hold the result of the operationregexMatch
- boolean, if the destination string is a regex string to match.
String var = "result";
String source = "hello";
String destination = "^[h|H]ello?$";
if(Strings.Compare(source, destination, var))
System.out.println("Compare success: result is "+GetVariableValue(var));//expected result 'true'
source = "hell";
if(Strings.Compare(source, destination, var))
System.out.println("Compare success: result is "+GetVariableValue(var));//expected result 'true'
//without leading ^ and ending $, the regex will match the substring of source string.
destination = "[h|H]ello?";
source = "Hi, hello Matt.";//sub-string "hello" will match the regex
if(Strings.Compare(source, destination, var))
System.out.println("Compare success: result is "+GetVariableValue(var));//expected result 'true'
public static boolean Concatenate(java.lang.String str1, java.lang.String str2, java.lang.String resultVar)
str1
- String, string to concatenatestr2
- String, string to concatenateresultVar
- String, the variable to hold the result of the operation
String var = "result";
String str1 = "hello";
String str2 = " world";
if(Strings.Concatenate(str1, str2, var))
System.out.println("Concatenate success: result is "+GetVariableValue(var));//expected result 'hello world'
public static boolean GetField(java.lang.String source, int index, java.lang.String delimiters, java.lang.String resultVar)
source
- String, The input string which contains the field to be returnedindex
- int, 0-based indexdelimiters
- String, one or more single characters used as delimitersresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a|bc|d";
int index = 1;
String delimiter = "|";
if(Strings.GetField(source, index, delimiter, var))
System.out.println("GetField success: result is "+GetVariableValue(var));//expected result'bc'
public static boolean GetFieldCount(java.lang.String source, int index, java.lang.String delimiters, java.lang.String resultVar)
source
- String, The input string to parse and count fieldsindex
- int, 0-based index, start-index for parsing the stringdelimiters
- String, one or more single characters used as delimitersresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a|bc|d";
int index = 0;
String delimiter = "|";
if(Strings.GetFieldCount(source, index, delimiter, var))
System.out.println("GetFieldCount success: result is "+GetVariableValue(var));//expected result '3'
public static boolean GetFixedWidthField(java.lang.String source, int fieldID, int fixedWidth, java.lang.String resultVar)
source
- String, The input string to parsefieldID
- int, 0-based field to retrievefixedWidth
- int, the fixed width allotted for each field in the recordresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abcdef";
int fieldID = 1;
int fixedWidth = 2;
if(Strings.GetFixedWidthField(source, fieldID, fixedWidth, var))
System.out.println("GetFixedWidthField success: result is "+GetVariableValue(var));//expected result 'cd'
public static boolean GetMultiDelimitedField(java.lang.String source, int fieldID, int startIndex, java.lang.String delimiters, java.lang.String resultVar)
source
- String, The input string to parsefieldID
- int, 1-based field to retrievestartIndex
- int, 1-based start position for search in sourceStringdelimiters
- String, one or more single characters used as delimitersresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a->b->c->d->e->f";
int fieldID = 2;
int startIndex = 5;
String delimiters = "->";
if(Strings.GetMultiDelimitedField(source, fieldID, startIndex, delimiters, var))
System.out.println("GetMultiDelimitedField success: result is "+GetVariableValue(var));//expected result 'c'
public static boolean GetMultiDelimitedFieldCount(java.lang.String source, int startIndex, java.lang.String delimiters, java.lang.String resultVar)
source
- String, The input string to parsestartIndex
- int, 1-based start position for search in sourceStringdelimiters
- String, 1-based start position for search in sourceStringresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a->b->c->d->e->f";
int startIndex = 1;
String delimiters = "->";
if(Strings.GetMultiDelimitedFieldCount(source, startIndex, delimiters, var))
System.out.println("GetMultiDelimitedFieldCount success: result is "+GetVariableValue(var));//expected result '6'
public static boolean GetNextDelimiterIndex(java.lang.String source, int startIndex, java.lang.String delimiters, java.lang.String resultVar)
source
- String, The input string to parsestartIndex
- int, 0-based start-index to begin parsing the string.delimiters
- String, each character is treated as a separate delimiterresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a/|/";
int startIndex = 0;
String delimiters = "/|";
if(Strings.GetNextDelimiterIndex(source, startIndex, delimiters, var))
System.out.println("GetNextDelimiterIndex success: result is "+GetVariableValue(var));//expected result '1'
public static boolean GetREDelimitedField(java.lang.String source, int index, java.lang.String regexDelimiters, java.lang.String resultVar)
source
- String, The input string to parseindex
- int, 1-based index of the field to return from the input string.regexDelimiters
- String, regular expression used as the delimiter(s).resultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a|b&cd-efghi";
int index = 3;
String delimiters = "[\|&\-g]";
if(Strings.GetREDelimitedField(source, index, delimiters, var))
System.out.println("GetREDelimitedField success: result is "+GetVariableValue(var));//expected result 'cd'
public static boolean GetREDelimitedFieldCount(java.lang.String source, int startIndex, java.lang.String regexDelimiters, java.lang.String resultVar)
source
- String, The input string to parsestartIndex
- int, 0-based index of where to start the analysis from.regexDelimiters
- String, regular expression used as the delimiter(s).resultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a|b&cd-efghi";
int startIndex = 0;
String delimiters = "[\|&\-g]";
if(Strings.GetREDelimitedFieldCount(source, startIndex, delimiters, var))
System.out.println("GetREDelimitedFieldCount success: result is "+GetVariableValue(var));//expected result '5'
public static boolean GetSubstringsInString(java.lang.String source, java.lang.String regexStart, java.lang.String regexStop, java.lang.String resultVar)
source
- String, The input string to parseregexStart
- String, The starting regular expression. Should not be empty.regexStop
- String, The stopping regular expression. Should not be empty.resultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "XaaaB";
String start = "X";
String end = "B";
if(Strings.GetSubstringsInString(source, start, end, var))
System.out.println("GetSubstringsInString success: result is "+GetVariableValue(var));//expected result 'aaa'
public static boolean GetSystemEnviron(java.lang.String systemVariable, java.lang.String resultVar)
systemVariable
- String, The system variable name.resultVar
- String, the variable to hold the result of the operation
String var = "result";
String systemVariable = "OS";
if(Strings.GetSystemEnviron(systemVariable, var))
System.out.println("GetSystemEnviron success: result is "+GetVariableValue(var));//expected result, something like 'Windows_NT'
public static boolean GetSystemUser(java.lang.String resultVar)
resultVar
- String, the variable to hold the result of the operation
String var = "result";
if(Strings.GetSystemUser(var))
System.out.println("GetSystemUser success: result is "+GetVariableValue(var));//expected result 'logged-in user'
public static boolean GetTrimmedField(java.lang.String source, int index, java.lang.String delimiters, java.lang.String resultVar)
source
- String, The input string to parseindex
- int, 0-based index of which field to grab .delimiters
- String, each character is treated as a separate delimiter.resultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "a|bc|d";
int index = 1;
String delimiters = "|";
if(Strings.GetTrimmedField(source, index, delimiters, var))
System.out.println("GetTrimmedField success: result is "+GetVariableValue(var));//expected result 'bc'
public static boolean Index(int startIndex, java.lang.String source, java.lang.String findString, java.lang.String resultVar)
startIndex
- int, 0-based starting offset of the sourceString to search.source
- String, The input string to parsefindString
- String, the string to find.resultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
int index = 0;
String findString = "bc";
if(Strings.Index(index, source, findString, var))
System.out.println("Index success: result is "+GetVariableValue(var));//expected result '1'
public static boolean Left(java.lang.String source, int length, java.lang.String resultVar)
source
- String, The input string to parselength
- String, number of chars to copyresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
int length = 1;
if(Strings.Left(source, length, var))
System.out.println("Left success: result is "+GetVariableValue(var));//expected result 'a'
public static boolean LeftTrim(java.lang.String source, java.lang.String resultVar)
source
- String, The input string to parseresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = " abc ";
if(Strings.LeftTrim(source, var))
System.out.println("LeftTrim success: result is "+GetVariableValue(var));//expected result 'abc '
public static boolean Length(java.lang.String source, java.lang.String resultVar)
source
- String, The input string to parseresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
if(Strings.Length(source, var))
System.out.println("Length success: result is "+GetVariableValue(var));//expected result '3'
public static boolean Replace(java.lang.String source, java.lang.String find, java.lang.String replace, java.lang.String resultVar)
source
- String, The input string to parsefind
- String, The string to findreplace
- String, The string used to replaceresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
String find = "bc";
String replace = "123";
if(Strings.Replace(source, find, replace, var))
System.out.println("Replace success: result is "+GetVariableValue(var));//expected result 'a123'
public static boolean Right(java.lang.String source, int length, java.lang.String resultVar)
source
- String, The input string to parselength
- String, number of chars to copyresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
int length = 2;
if(Strings.Right(source, length, var))
System.out.println("Right success: result is "+GetVariableValue(var));//expected result 'bc'
public static boolean RightTrim(java.lang.String source, java.lang.String resultVar)
source
- String, The input string to parseresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = " abc ";
if(Strings.RightTrim(source, var))
System.out.println("RightTrim success: result is "+GetVariableValue(var));//expected result ' abc'
public static boolean SubString(java.lang.String source, int start, int length, java.lang.String resultVar)
source
- String, The input string to parsestart
- int, 0-based offset character positionlength
- int, number of chars to copyresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
int start = 1;
int length = 1;
if(Strings.SubString(source, start, length, var))
System.out.println("SubString success: result is "+GetVariableValue(var));//expected result 'b'
public static boolean ToLowerCase(java.lang.String source, java.lang.String resultVar)
source
- String, The input string to parseresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "ABC";
if(Strings.ToLowerCase(source, var))
System.out.println("ToLowerCase success: result is "+GetVariableValue(var));//expected result 'abc'
public static boolean ToUpperCase(java.lang.String source, java.lang.String resultVar)
source
- String, The input string to parseresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = "abc";
if(Strings.ToUpperCase(source, var))
System.out.println("ToUpperCase success: result is "+GetVariableValue(var));//expected result 'ABC'
public static boolean Trim(java.lang.String source, java.lang.String resultVar)
source
- String, The input string to parseresultVar
- String, the variable to hold the result of the operation
String var = "result";
String source = " abc ";
if(Strings.Trim(source, var))
System.out.println("Trim success: result is "+GetVariableValue(var));//expected result 'abc'
Copyright © SAS Institute. All Rights Reserved.