• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

appending with spaces ????

 
subu ananthram
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My instruction spec say that I need to null terminate everything whose size is less than the max size from the looks of it the db supplied from sun appends spaces and hence the size of each word is never less than the size 8

This is a little confusing ...I am thinking of creating a string which is totally empty whose size is equal to the size of the record..
so something like

private static String getStringPaddedWithSpaces(long recordLength2) {

StringBuilder temp=new StringBuilder();
for(int i=0;i<recordLength2;i++)
temp.append(" ");
String s=temp.toString();
return s;
}

so this should give me a totally empty string and then
I have a stringBuilder and I do somethign similar to what Andrew does in this book I call stringBuilder's replace method and replace what I want in the string....
Is this ok???
What happens if the user wants to insert something bigger than 8 bytes do I flag this as an error or do I truncate after 8 bytes?
Subu
 
subu ananthram
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose I want to insert something like 'Tom'sRestaurant' all one word
Size of the text is grated than 8
so do I break this after 8 bits and then append spaces for the rest?

Subu
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
classic case of the specifications not matching reality.
Do what you like, but document your decision.
 
subu ananthram
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply
I am still a bit queasy about totally ignoring the rule for texts that have size greater than 8...wondering if it will lead to sure failure ..........I dont like the idea of breaking the text when its size is greater as well..... So at the moment in two minds
What is the general way adopted
Any ideas...
Regards
Subu
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you can only store 8 characters, you can only store 8 characters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic