• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

How to find and replace a substring from a given string

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone

I want to know that how can we find a substring in a given string without using string functions, although we can use length() function.

It can be easily done in C/C++ because in these(C/C++) Strings are array of characters , but as you know in java we consider Strings as objects.

So please try to write a code for it using java .

For Example:-

we get a string HELLOINDIA , now we want to replace INDIA with WORLD , so that it becomes HELLOWORLD .


Also please explain how can we convert a given String into an array of characters .





Thank you

With Regards
Armaan Lovras
 
author and iconoclast
Posts: 24208
47
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a method in String which returns an array of characters for the String; there's also a method which returns the character at a given index. Look at the Javadoc for the java.lang.String class to find them.

Nothing you do can change an actual String object, by the way; all you can do is make a new String with a new value. Strings are immutable -- they have no methods which allow you to change the characters they contain.

In C++ a string is not just an array of characters, by the way; it's an object. A char* is, of course, just a pointer to some characters; but "string" is a kind of object in C++ just as in Java.
 
reply
    Bookmark Topic Watch Topic
  • New Topic