Re: how to insert space in a string



On 10月31日, 下午10時42分, KC <kenchen...@xxxxxxxxx> wrote:
Hi all,

I m new in Java, Im not know well about Java syntax, for now, I need
to reform a string var, find out the newline char ( "\r\n" ) and
replace it with specify no. of Space char ( " " ), in order to get the
result string char with 50 * (no.of line) char,

example as blow:
" The group you are posting to is a Usenet group.\r\nMessages posted
to this group\r\nWill make your email address\r\n"

orginal sting change it into

"The group you are posting to is a Usenet group. " +
"Messages posted to this group
" +
"Will make your email
address "

for each line contains exactly 50 char

Thx all for attention,


"The group you are posting to is a Usenet group.\r\nMessages posted to
this group\r\nWill make your email address\r\n"

for 1st line: "The group you are posting to is a Usenet group.\r\n"
contains 46 char, that means insert 4 more space char reform to
exactly 50 chat string
"The group you are posting to is a Usenet group. "

for 2nd line: "Messages posted to this group\r\n"
contains 28 char, that means insert 22 more space char reform to
exactly 50 chat string
"The group you are posting to is a Usenet group.
"
.



Relevant Pages

  • Re: How to add thousand separators
    ... First, this code is obsolete as written, because char is a dead data type and should not ... Note that both of these should be stored as string resources since they might need to be ... 18 digits for any reason. ... you have made a VERY SERIOUS DESIGN ERROR. ...
    (microsoft.public.vc.mfc)
  • Re: what is the best way of passing floats into a string
    ... I do not null-terminate as snprintf takes care of this (according to ... But the easiest way to determine the size needed to format a number, ... int length_of_representation(double n,const char* format){ ... I get a nice result of -10.000000 in my char * string. ...
    (comp.unix.programmer)
  • Re: weird problem
    ... I already told you that the comparison between an integer and a float ... to strcmpwhich expects a pointer to a string. ... And now a question about something else: why do you use floating ... int,float, char, etc. ...
    (comp.lang.c)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you don't use char, an obsolete data type ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you don't use char, an obsolete data type ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)