cancel
Showing results for 
Search instead for 
Did you mean: 

Position in an Array

Former Member
0 Kudos

Hey all

I have asked this question before but I realized I did not give enough info, sorry

I am new to PI/java and I am trying to write a UDF, Here is the UDF requirements:

If account starts with an u201Cxu201D, replace with u201C4u201D. If account starts with 17**, and not equal to 1783 or 1784 or 1794 or 1795 or 1796 or 1797 or 1791 or 1799, replace with u201C1790u201D, ELSE map actual value.

I also want to note that the account numbers start in the position 4-8 in an array of 26 characters (so I know substring will need to be used) and also that I have to return the entire 26 charaters with the changes.

Can anyone help me?

Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

anupam_ghosh2
Active Contributor
0 Kudos

Hi,

This is another way you can achieve your target


public static String ReplaceChar(String s)
	{
		try
		{
			int i;
			if(s.charAt(4)=='x' || s.charAt(4)=='X') 
			{
				s=s.substring(0,4)+"4"+s.substring(5);
			}
			else if(s.substring(4, 6).equals("17"))
			{
				try
				{
					i=new Integer(s.substring(4, 8)).intValue();
				}
				catch(NumberFormatException e)
				{
					return s;
				}
				if(i==1783 || i==1784 || (i>=1794 && i<=1797) || i==1791 || i==1799)
				{
					s=s.substring(0, 4)+"1790"+s.substring(8);
				}
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return s;
		
	}

Input output is shown below

Input => Output

01231783y67891011 => 01231790y67891011

0123x4569897897 => 012344569897897

012317y43543543 => 012317y43543543

01231799y67891011 => 01231790y67891011

01231798y67891011 => 01231798y67891011

one small request from my end, I think you have raised same question in multiple threads. This might cause confusions about your query itself. In case you feel you need to modify or reframe your question you can do in the same thread (where you raised the query for first time) instead of creating a new thread. I feel in that way forum user's know that you have reframed your question, and accordingly they can (if they want) reframe their answers.

regards

Anupam

Edited by: anupamsap on Jul 13, 2011 11:08 AM

Former Member
0 Kudos

Hi,

Please try this out.

String code = "fpl179701105031052374666.dat";
		StringBuffer buffer1 = new StringBuffer(code);
		StringBuffer buffer = new StringBuffer(code.substring(3,7));
		String accnt = code.substring(3,7);
		System.out.println(accnt);
		if(accnt.startsWith("x"))
			buffer.replace(0, 1, "4");
		else if(accnt.startsWith("17")){
			if((accnt.equals("1783"))|| (accnt.equals("1784"))||(accnt.equals("1794"))||(accnt.equals("1795")));
			else
				buffer.replace(0, 4, "1790");
		}
		buffer1.replace(3, 7, buffer.toString());
		
		System.out.println(buffer1);

Please make changes and add the conditions accordingly