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 


code golf? Normalize an AOB String

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

Joined: 01 Oct 2008
Posts: 636

PostPosted: Fri Feb 17, 2017 11:46 am    Post subject: code golf? Normalize an AOB String Reply with quote

Normalize AOB string
1. DIGIT here can be wildcard(?) or hexidecimal;
2. aob is separated by spaces into parts;
3. any non-hexadecimal DIGIT chars in part is turn to wildcard DIGIT(?);
4. if count of chars in part is odd, last digit is prefix with '0' if hexadecimal, or '?' if not;
5. then normalize aob is consecutive 2 DIGIT (excluding space) separated by single space.

--Lua :
Code:

function aobNorm(aob)
  return aob:gsub("[^%x%s]","?"):gsub("%S%S?",function(hx)
    if hx:len()==1 then return hx:match"%x" and '0'..hx or '??'end
  end):gsub("%s+",""):gsub(".."," %1"):sub(2):upper()
end

print(aobNorm" ? 11 2? ?3   44556 __ 8899 a??b cc??ee? ? ")
-- ?? 11 2? ?3 44 55 06 ?? 88 99 A? ?B CC ?? EE ?? ??


The post is originally for me to ask how C# to do regular expression substitution effectively (it seems complicated, MatchEvaluator etc ~_~), but any language is welcome, and not necessary by regex.

Thank you~

_________________
- Retarded.
dropbox
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 133

Joined: 25 Jan 2006
Posts: 7059
Location: 127.0.0.1

PostPosted: Thu Mar 02, 2017 4:01 am    Post subject: Reply with quote

Lua and a language like C# handle pattern matching much differently. Lua does its own thing with no real standardization being met while C# attempts to conform to more common standards (and can be directed to confirm to specifics such as ECMA).

For the first part, as an example, you could do the gsub in C# like this:

Code:

// Default input string..
var s = " ? 11 2? ?3   44556 __ 8899 a??b cc??ee? ? ";

// Do the replace, which should make the __'s become ??'s..
var result = Regex.Replace(s, @"([^a-fA-F0-9\s])", "?");

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
panraven
Grandmaster Cheater
Reputation: 25

Joined: 01 Oct 2008
Posts: 636

PostPosted: Sat Mar 25, 2017 4:23 pm    Post subject: Reply with quote

Sorry for late reply and thank you for the response.

To make the code more Lua-alike, I later found Extension Method is one way, may be trivial, https://msdn.microsoft.com/en-us//library/bb383977.aspx

_________________
- Retarded.
dropbox
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