469,323 Members | 1,665 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

byte stuffing

Hi i send characters to a server with escape character 'e' and flag 'f'. But now i dont know how to extract the original string. I thought maybe this method would work but i was wrong. any help plz?

Original String = "ref"
frame = "freeeff"
extracted content must be "ref" again.


Expand|Select|Wrap|Line Numbers
  1. public String content()
  2. {
  3.     char wrd[] = words.toCharArray();
  4.     String con = "";
  5.     for(int i=1; i < (wrd.length-2); i++ )
  6.     {
  7.         if(wrd[i] == 'e'){
  8.         con += wrd[i+1];
  9.         i++;
  10.         }
  11.         else
  12.           con += wrd[i];  
  13.  
  14.  
  15.     }
  16.     return con;
  17. }
Aug 10 '09 #1
5 10155
JosAH
11,448 Expert 8TB
@Elaine121
What are the exact rules for your en/decoding? i.e. when do you add an 'e' or an 'f'?

kind regards,

Jos
Aug 10 '09 #2
the 'f' is added at the start and end of the string to indicate the beginning and end. if there is an 'f' in the actual string you place an 'e' in front so you will know it is an f and not the end of the string. because an 'e' is used it must also be place in front of any 'e' that is in the original string.

another example: "hello friend" would be: "fheello efrieendf".
Aug 10 '09 #3
JosAH
11,448 Expert 8TB
Well, as far as I can see your code works; it just stops one character too early: make that loop terminating condition i <= (wrd.length-2) and all should be fine.

kind regards,

Jos
Aug 10 '09 #4
the problem i get is instead of displaying "ref" it just displays "r f".
Aug 11 '09 #5
never mind i got it to work. Thanx for the help
Aug 11 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by David Cook | last post: by
4 posts views Thread by sarath1111 | last post: by
13 posts views Thread by Ray Z | last post: by
6 posts views Thread by Dennis | last post: by
4 posts views Thread by Frederick Gotham | last post: by
10 posts views Thread by Scott Townsend | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.