Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Java] Is there some type of sizeOf() function for Java?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Tue May 01, 2012 9:06 pm    Post subject: [Java] Is there some type of sizeOf() function for Java? Reply with quote

I'm converting a text file with records to a RandomAccessFile and I want each record to be uniform length, so I need to add some garbage/filler bytes to the end of my shorter records. In that case, I need to figure out what the max possible byte size/length of the record could be. Each record consists of ints, strings, and doubles. Is there some simple way to figure out the size of variables in Java? Sad

Alternatively, I could just take the whole record as a string....but my problem is still figuring out how many bytes are in a string.

_________________
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Tue May 01, 2012 10:30 pm    Post subject: Reply with quote

Integer.MAX_VALUE or Integer.SIZE

http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Tue May 01, 2012 10:54 pm    Post subject: Reply with quote

Ok, actually using .SIZE did help me find the number of bits in an int (and double also). However I'm realizing that I only need to find the amount of bytes in a string.

This might be a dumb question, but can different strings of the same length have different byte size values?

If not, then my problem is almost solved...

_________________
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Tue May 01, 2012 11:00 pm    Post subject: This post has 1 review(s) Reply with quote

Quote:

This might be a dumb question, but can different strings of the same length have different byte size values?

If not, then my problem is almost solved...


A byte is always 8-bits. Max value of 0xFF (255)

Quote:

Ok, actually using .SIZE did help me find the number of bits in an int (and double also). However I'm realizing that I only need to find the amount of bytes in a string.




The number of bytes in a string can be obtained with the length function.


Last edited by 661089799107 on Tue May 01, 2012 11:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Tue May 01, 2012 11:15 pm    Post subject: Reply with quote

I appreciate the help man. However, someString.length() will return the length of the string in unicode characters, not the bytes. This could still be useful though.... If all strings of the same length require the same amount of bytes than I can just add spaces to make all my strings the same size, and therefore all my records will have uniform byte size.

So, again, do all strings of the same length require the same amount of bytes?

For example, would "436fjg937t" require the same amount of bytes as "m'9shqIdm0" ? They're both 10 characters long, but the content is different.

_________________
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Tue May 01, 2012 11:16 pm    Post subject: Reply with quote

Quote:
I appreciate the help man. However, someString.length() will return the length of the string in unicode characters, not the bytes.


The below code would output the same result.
Code:

String s = "abc";

System.out.println(s.length());
System.out.println(s.getBytes().length);



Quote:

So, again, do all strings of the same length require the same amount of bytes?

For example, would "436fjg937t" require the same amount of bytes as "m'9shqIdm0" ? They're both 10 characters long, but the content is different.


436fjg937t=52 51 54 102 106 103 57 51 55 116 (10 bytes)
m'9shqIdm0=109 39 57 115 104 113 73 100 109 48 (10 bytes)
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Tue May 01, 2012 11:37 pm    Post subject: Reply with quote

That about answers my question.
Srsly though, I appreciate it <3

Actually I have more unrelated questions, but rather than make a new thread:

If I have strings : "4563 654564 Smith Will ...etc" , "324 235 Jones Mary..etc"

How could I get the first *actual* word? I basically want to parse from the 2nd space to the third space regardless of the lengths of the stuff in between them. (i.e. I just want Smith and Jones)

_________________
Back to top
View user's profile Send private message
NotReallySureWhatGoesHere
Expert Cheater
Reputation: -1

Joined: 20 Feb 2012
Posts: 110

PostPosted: Wed May 02, 2012 9:27 pm    Post subject: Reply with quote

manc wrote:
That about answers my question.
Srsly though, I appreciate it <3

Actually I have more unrelated questions, but rather than make a new thread:

If I have strings : "4563 654564 Smith Will ...etc" , "324 235 Jones Mary..etc"

How could I get the first *actual* word? I basically want to parse from the 2nd space to the third space regardless of the lengths of the stuff in between them. (i.e. I just want Smith and Jones)


Have some type of separator (|, ::, etc.) and http://www.rgagnon.com/javadetails/java-0438.html. Use an index of the new String array to find a particular String.
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Thu May 03, 2012 1:17 am    Post subject: Reply with quote

manc wrote:

Actually I have more unrelated questions, but rather than make a new thread:

If I have strings : "4563 654564 Smith Will ...etc" , "324 235 Jones Mary..etc"

How could I get the first *actual* word? I basically want to parse from the 2nd space to the third space regardless of the lengths of the stuff in between them. (i.e. I just want Smith and Jones)


By using regular expressions.

Code:

      String s = "4563 654564 Smith Will";
      
      Matcher matcher = Pattern.compile("\\s[A-Za-z]+\\s").matcher(s);
      
      if(matcher.find())
         System.out.println(matcher.group().trim());
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites