codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Describing code segment (newbie stuff)  rsixtyone at 00:22 on Saturday, September 24, 2005
 

A.

String s = "perserverance";
String t = s.substring(4, 6);
String u = s.substring(3, 8);
String v = s.substring(0, 9);
System.out.println(t);
System.out.println(u);
System.out.println(v);

This is my explaination for the above code segment:

1. Takes the substream at the 5th character and stops at the 7th character in the string s.
2. Takes the substream at the 4th character and stops at 9th in the string s.
3. Takes the substream at the 1st character and stops at the 10th in the string s.

Is that correct? Is there any step after that? What is the output of it will look like?

  Re: Describing code segment (newbie stuff)  crwood at 00:47 on Saturday, September 24, 2005
 

class StringTest
{
public static void main(String[] args)
{
String s = "perserverance";
String t = s.substring(4, 6);
String u = s.substring(3, 8);
String v = s.substring(0, 9);
System.out.println(t);
System.out.println(u);
System.out.println(v);
}
}
Is that correct?
substream should be substring. otherwise, yes

What is the output of it will look like?
C:\jexp>java StringTest
er
serve
perserver

<Added>

To avoid confusion, this:

Is that correct?
substream should be substring. otherwise, yes

might be more clear if written as:

Is that correct?
1. Takes the substream at the 5th character and stops at the 7th character in the string s.
"substream" in the statement above should be "substring". otherwise, yes

  Re: Describing code segment (newbie stuff)  rsixtyone at 01:12 on Saturday, September 24, 2005
 

how would one describe this code segment

String s = "abracadabra";
int n1 = s.indexOf("ra");
int n1 = s.indexOf("ra", 2);
int n1 = s.indexOf("ra", 5);
int n1 = s.indexOf("ra", 10);
System.out.println(n1);
System.out.println(n2);
System.out.println(n3);
System.out.println(n4);








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Date script issues
•  perl script help needed
•  onChange issue
•  perl remote execution
•  Chat application
•  How to send multiple perameters in SOAP request.
•  Java code for Insert picture on the table in spreadsheet
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007