|
I am having trouble changing text form upperCase to lowerCase. I am trying to read in a file and change the first letter of the word to lowerCase and the second word to upperCase and delete the spaces in between. Example:
Control Measure Mapping (needs to look like) controlMeasureMapping. I have provided the code that I have so far. If anyone can HELP, I would really appreciate it.
import java.io.*;
import javax.swing.*;
class BufferReaderDemo {
public static void main(String args[]) {
try {
FileReader fr = new FileReader("/forum/CDocuments_and_SettingsrwhitehurstDesktopTest.txt");
BufferedReader br = new BufferedReader(fr);
String s;
int ToCharArray[] = new int[4];
String output = "Index\tValue\n";
while((s = br.readLine()) != null){
if (s.length() > 0)
{
}
System.out.println(s);
}
fr.close();
}
catch(Exception e) {
System.out.println("Exception: " + e);
}
}
}
|
|
|
suppose u have a string like below
String abc="Kamal Khan Great"
create an array type variable and split abc string with space
Array splitstring=abc.Split(" ")
create another string variable like below
String Resultstring= splitstring(0).ToLower()
Resultstring += Resultstring(1) & Resultstring(2)
|
|
|
try the following code.
import java.io.BufferedReader;
import java.io.FileReader;
public class BufferReaderDemo
{
public static void main(String args[])
{
try
{
FileReader fr = new FileReader("/forum/CTest.txt");
BufferedReader br = new BufferedReader(fr);
String s;
int tmp=0;
String ostring = "";
String nstring="";
while((s = br.readLine()) != null)
{
ostring=ostring+s;
}
fr.close();
br.close();
for(int k=0;k<ostring.length();k++)
{
if((int)ostring.charAt(k)!=32)
{
nstring=nstring+ostring.charAt(k);
}
}
if((int)ostring.charAt(0)>=65 && (int)ostring.charAt(0) <=90)
{
tmp = (int)ostring.charAt(0)^32;
nstring=nstring.replace(ostring.charAt(0),(char)tmp);
}
System.out.println("nstring is " + nstring);
}
catch(Exception e)
{
System.out.println("Exception: ");
e.printStackTrace();
}
}
}
|
|
Thanks.
|
|
|
|
|
|
|
|