Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Gene Taylor   on Oct 04 In Java Category.

  
Question Answered By: Topaz Ramirez   on Oct 04

> (1) Finding a substring (say, aString ='efg') within the main string
> (eg, mainString = 'abcdefghijklm'). The mainString will have NOT have
> a fixed range of characters.

Do a Google search on "string matching" or "pattern matching". There
are many algorithms for doing this. Some simpler than others.

> (2) I know how to get length of a string, but is there a way to
> answer in an integer format (which I'd use in a FOR statement later
> on)? Eg. I get a length of 5 - how can I convert that into a integer
> variable. Note: I don't want to alter the String! Just get a integer
> output for length.

String.length() returns an int.

>
> (3) Convert a String into separate characters. Eg a string
> of 'abcde'. would be converted into five DISTINCT characters A B C D
> E that I could then perform calculations against. Again it's not
> fixed.

Here's the code to turn a String into a char array. char may be
replaced with the Character wrapper class.

char cArr[] = new char[s.length];
for(int i = 0; i < s.length(); i++){
cArr[i] = s.charAt[i];
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Some help with Strings would be nice! Or get search suggestion and latest updates.


Tagged: