Solved

How to replace a letter with other letter?

Posted on 2004-10-05
4
220 Views
Last Modified: 2010-04-01
Dear all,

I want to replace each letter that user entered as following:

input     output
a            ah
e            eh
i             ee or ih
o            oh
ö            er
u            oo
ch           sh
au          ow
ei           eye
eu, äu     oy
ie           ee
j             y
qu           kv
s             z or ss
ß             ss
sp           shp
st            sht
sch          sh
th            t
v             f
w            v
z             ts


for example, if user enter 'wie heißt du', then the output is 'vee heyesst doo'. so what is the complete code to convert each letter of user input (if the letter matched one of the input list) into its output ?

Thanks for everyone who can provide the solution.

Regards,
ahwind
0
Comment
Question by:ahwind
  • 2
4 Comments
 
LVL 7

Expert Comment

by:a1programmer
ID: 12230312
how do you determine whether i should be ee or ih ?  and if e always follows i, so that you get ie, do you always output ee, and ignore the i ?
0
 

Author Comment

by:ahwind
ID: 12235537
Dear a1programmer,


Yes, u r right! if i found letter e in the input, then i should check whether it is followed by i or u. if it is i, then i should convert the 'ei' in input into 'eye'.else if it is followed by 'u', the output should be 'oy'. otherwise, just convert the 'e' into 'eh'.

well, the new list is defined as follow:
input     output
a            ah
e            eh
i             ee
o            oh
ö            er
u            oo
ch           sh
au          ow
ei           eye
eu, äu     oy
ie           ee
j             y
qu           kv
s             ss
ß             ss
sp           shp
st            sht
sch          sh
th            t
v             f
w            v
z             ts

is that clear? so may you help me to work out the complete source code ? thanks!

Regards,
ahwind
0
 
LVL 7

Expert Comment

by:a1programmer
ID: 12237965
Sure... Is this actually going to be done using jsp?
0
 

Accepted Solution

by:
msasikala earned 125 total points
ID: 12256607
Hi,
  keep the following method in some util file and use it whereever u want to replace the string

public static String replace(String str)
{
String [] input={"a","e","i","o","ö","u","ch","au","ei","eu","äu","ie","j","qu","s","ß","sp","st","sch","th","v","w","z"};
String[] output={"ah","eh","ee","oh","er","oo","sh","ow","eye","oy","oy","ee","y","kv","ss","ss","shp","sht","sh","t","f","v","ts"};

char[] ch;
String temp;
int len=str.length();
StringBuffer strBuf=new StringBuffer();
boolean bool;

for(int i=0;i<len;i++)
{
     ch=new char[1];
     ch[0]=str.charAt(i);
     temp=new String(ch);
     bool=false;
     if( (temp.equals("i") || temp.equals("e") )&&(i<len-1) )
    {
      ch=new char[2];
      ch[0]=str.charAt(i);
      ch[1]=str.charAt(i+1);
      temp=new String(ch);
      if( (temp.equals("ie"))|| (temp.equals("ei")) ||(temp.equals("eu")) )      {
          for(int k=0;k<input.length;k++)
          {
            if(temp.equals(input[k]))
                    strBuf.append(output[k]);
          }
          continue;
      }else{
                for(int k=0;k<input.length;k++)
                {  
                if(temp.equals(input[k]))
                  strBuf.append(output[k]);
                }
            }
      }else{
            for(int k=0;k<input.length;k++)
            {  
                 if(temp.equals(input[k])){
                  strBuf.append(output[k]);
                  bool=true;
                  }
            }
            if(!bool)
                strBuf.append(temp);
               }
            }
      return strBuf.toString();

}
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now