Solved

How to replace a letter with other letter?

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running Java Servlet inside Eclipse Luna 6 158
JSP Popup page 2 116
web service Rest Client creation 4 87
Suggestion on WebSite Template Sites 6 101
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This problem is more common than not and I will show you some things to check to solve this problem.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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