|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Fri Feb 17, 2017 11:46 am Post subject: code golf? Normalize an AOB String |
|
|
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. |
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Thu Mar 02, 2017 4:01 am Post subject: |
|
|
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 |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Sat Mar 25, 2017 4:23 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
|
|
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
|
|