Solved

Email Client/Server : Splitting up A String

Posted on 2004-04-04
13
263 Views
Last Modified: 2008-03-03
The server stores the message as a string. When the client selects an email to read, i want to display the message but only 50 characters per line. So, a few questions.
1. Should the server send 50 characters at a time, and then the client can just readLine and print. If so, whats the best way for the server to split the string and send.
2. Should the server send the whole string, and then client can split it up and print. I dont see a real difference except that in a real world application you would want the client doing more of the work.
3. Is there a better way?

Thanks
0
Comment
Question by:tricks801
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10752877
The number of characters per line belongs to the view of a data model. The data model in this case is the message string. Depending on what is inspecting this message, you can change the view to display as many characters per line you wish. Typically this is done in the real world by an email client and is implemented by line wrap in the message display area. The data model remains constant
0
 

Author Comment

by:tricks801
ID: 10752895
right...but im using the console, and would  not like to scroll right to read the long string.  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10752913
So the console view could be something like

a. Put the message into a StringBuffer
b. Insert a newline character '\n' every 50 characters
c. Turn it back into a String and print it

or

a. Iterate the char array (char[] messageChars = message.toCharArray())
b. System.out.print(......the message char or if index % 50 == 0, a newline character)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10752932
Personally i prefer the second one:


char[] messageChars = message.toCharArray();
for(int i = 0;i < messageChars;i++) {
      if (i % 50 == 0 && messageChars[i] != '\n') {
            System.out.print('\n');
      }
      else {
            System.out.print(messageChars[i]);      
      }
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10752938
But don't leave that literal 50 in the real thing of course
0
 

Author Comment

by:tricks801
ID: 10753077
so this should happen client side and the server is still going to send one long string? Is this the message in message.toCharArray()?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 10753080
Yes
0
 
LVL 30

Assisted Solution

by:GrandSchtroumpf
GrandSchtroumpf earned 200 total points
ID: 10753346
CEHJ, your code would break the original formatting.
I think something like this would be more appropriate:

for(int i = 0; i < messageChars.length; i++, linechars++) {
     System.out.print(messageChars[i]);
     if (messageChars[i] == '\n') {
          linechars = 0;
     }
     if (linechars >= 50) {
          linechars = 0;
          System.out.print('\n');
     }
}
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10753358
with a declaration and initialization for my linechars variable it would be even better:
int linechars = 0; // before the for loop;
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 10753604
int LEN = 50;

while (line.length()>LEN)
{
    System.out.println(line.substring(0, LEN));
    line = line.substring(LEN);
}
if (line.length()>0) System.out.println(line);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10824325
8-)
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10826081
:°)
0
 
LVL 92

Expert Comment

by:objects
ID: 10827864
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 128
oracle 11g 23 51
difference of if loops 23 43
javap not working 8 39
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now