471,887 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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];  
  15.     }
  16.     return con;
  17. }
Aug 10 '09 #1
5 10913
11,448 Expert 8TB
What are the exact rules for your en/decoding? i.e. when do you add an 'e' or an 'f'?

kind regards,

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
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,

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
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.