cancel
Showing results for 
Search instead for 
Did you mean: 

About string function

Former Member
0 Kudos

Hi Experts,

in my scenario there is a value that is comming from source need to be substring depending on some condition eg: Electrical:Cable as per the req we need only Cable this could be achived by using the substring function but if there is a null value comming from the source then it should write a null at the target

but when we are using substring function to get the value eg Cable it works fine but when there is a null value it throws a error on substring function

can anyone provide the inputs as the req is critical

Thanks

Sampath

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Venkata.

There is a special function within java which returns the placement of this specific char. it's the indexOf()

Wen using this in the UDF you can use the response as input fot the subString Start

See snipplet below

posIndexofInString = inputString.indexOf(":",inputString)

when there is no ":" available in the string a value of -1 will be populated then choose

return inputString;

Else

if there is a ":" located in the string use (value of posIndexofInString is higher or equal to 0)

outString = inputString.substring(posIndexofInString);

Hope this is helpfull, if more info is required, please let me know.

Greets and Success

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

Alternatively you can use mapWithDefault and fixValues for this mapping:

source --> mapWithDefault: null --> fixValues --> target

e.g

Key <----


> Value

null <----


> null

Electrical:Cable <----


> Cable

In this way, you can specify the values without ever using the subString function.

Hope this helps,

Edited by: Mark Dihiansan on Feb 23, 2009 6:57 AM

Former Member
0 Kudos

Hi,

in graphical mapping, do the below:

Input Node -> equalS -> If -> Output Node

Constant([])-> Constant([])-> then

Input Node -> Substring ->else

Regards,

Rajeev Gupta

Former Member
0 Kudos

Hi,

You can try following UDF.

Inputs : iDVal - Input value

separator - :

position - 1

these inputs are for e.g Electrical:Cable

String[] splitCodes = null;		
for(int i = 0; i < iDVal.length; i++)
{
	splitCodes = iDVal<i>.split(separator[0]);
	int posVal = Integer.parseInt(position[0]);
	if(posVal < splitCodes.length)
	result.addValue(splitCodes[posVal]);
else
{result.addValue(ResultList.SUPPRESS);
}
}

-Rohit

Former Member
0 Kudos

Hi venkat,

Use the Below UDF(SubString). It works fine, even when the input given is null.

SourceField->UDF->TargetField

public static String SubString(String sInput, int iStartIndex, int iNoOfChars) {

int iLen = 0;

int iEndIndex = 0;

try {

iLen = sInput.length();

iEndIndex = iStartIndex + iNoOfChars;

if (iStartIndex > iLen)

return "";

if (iEndIndex > iLen)

iEndIndex = iLen;

} catch (Exception e) {

return "";

}

return sInput.substring(iStartIndex, iEndIndex);

}

Regards,

Swetha.