GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  General  >  Interests
Go To First  |  Previous Question  |  Next Question 
 Interests  |  Question 37 of 39    Print  
Replacing Characters in a String
// Replace all occurrences of 'a' with 'o'
String newString = string.replace('a', 'o');
Replacing Substrings in a String
static String replace(String str,
String pattern, String replace) {
int s = 0;
int e = 0;
StringBuffer result = new StringBuffer();
while ((e = str.indexOf(pattern, s)) >= 0) {
result.append(str.substring(s, e));
result.append(replace);
s = e+pattern.length();
}
result.append(str.substring(s));
return result.toString();
}
Converting a String to Upper or Lower Case
// Convert to upper case
String upper = string.toUpperCase();
// Convert to lower case
String lower = string.toLowerCase();
Converting a String to a Number
int i = Integer.parseInt("123");
long l = Long.parseLong("123");
float f = Float.parseFloat("123.4");
double d = Double.parseDouble("123.4e10");
Breaking a String into Words
String aString = "word1 word2 word3";
StringTokenizer parser =
new StringTokenizer(aString);
while (parser.hasMoreTokens()) {
processWord(parser.nextToken());



  
Total Answers and Comments: 0 Last Update: N/A   
  
 Sponsored Links

 

No answers are posted for this question yet.
Be the first to answer it!


 Related Questions

How is it possible for two String objects with identical values not to be equal under the == operator?
The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory. 

Constructing a StringIf you are constructing a string with several appends, it may be more efficient to construct it using a StringBuffer and then convert it to an immutable String object.StringBuffer 

String string = "aString";// First occurrence.int index = string.indexOf('S'); // 1// Last occurrence.index = string.lastIndexOf('i'); // 4// Not found.index = string.lastIndexOf('z'); 

// Replace all occurrences of 'a' with 'o'String newString = string.replace('a', 'o');Replacing Substrings in a Stringstatic String replace(String str,String pattern, 


 Sponsored Links

 
Related Articles

How ERP Improves General Ledger Capacity

How ERP Improves General Ledger Capacity Flexibility quickness and efficiency are the pillars and needs of the modern organization In order to fulfill all the requirements that the market imposes ERP has become an useful utility The general ledger tasks are nowadays one of the most important activit
 

C++ String Representation and Handling

C String Representation and Handling In this C tutorial you will learn about string representation and handling how is string represented end string notation initializing char array character representation string literals example programe to understand the character array concept and the accessing
 

JavaScript String Object

JavaScript String Object In this JavaScript tutorial you will learn about String Object purpose of string object in JavaScript purpose of string object indexof method lastIndexOf method and substring method along with syntax and example mosgoogle center Purpose of String Object in JavaScript The mai
 

Convert a String into an Integer

How to convert a string into an integer in C program? This is done by using the function named as atoi(). This function atoi() is present in the header file named as <stdlib.h>. When programmers use this function they must include the header file by the statement #include <stdl
 

String handling functions

What is the string handling functions present in header file <string.h>? There are number of string handling functions present in string.h. In other words if a programmer uses any of the function present in string.h then they must include the header file as #include <string.h&am
 

Convert a String into Long Value

What string function is used to convert a string into long value? This is done by using the function named as atol() . This function atol() is present in the header file named as <stdlib.h>. When programmers use this function they must include the header file by the statement
 

Base Address of the String

What happens when we try to change the value of base address of the string? The base address of the sting takes a special place in the context of strings. This is because suing this base address only the string gets identified. In other words the base address therefore takes the position of constant
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape