[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Email Client/Server : Splitting up A String

Posted on 2004-04-04
13
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 86

Accepted Solution

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

Assisted Solution

by:GrandSchtroumpf
GrandSchtroumpf earned 800 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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

656 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