Solved

How to replace a letter with other letter?

Posted on 2004-10-05
4
225 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 89
Jquery - parsing the results returned from webmethod 1 123
AlarmClock Challenge 35 155
Java Script nested call 3 88
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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