Jump to content
Tuts 4 You
Sign in to follow this  
LCF-AT

String value compare question

Recommended Posts

LCF-AT

Hi guys,

I have a short question again.I build a listview and show filenames & filedates into etc and now wanna add a sort function for the datetime.So it means I have to compare the datetime strings.How can I do this on a easy way?My format I use is this..like in explorer

03/12/2016 20:15:30
23/11/2015 21:05:32

Day,Month,Year,time.So can I compare it maybe at once anyhow?

greetz

Share this post


Link to post
kao

Best solution would be to compare actual datetimes, not strings.. :) 

One of the most common solutions is to store date value in LVITEM lParam field - this value is sent to your sorting function. See https://msdn.microsoft.com/en-us/library/windows/desktop/bb774760(v=vs.85).aspx and http://masm32.com/board/index.php?topic=610.0 and http://win32assembly.programminghorizon.com/tut31.html

  • Like 1

Share this post


Link to post
LCF-AT

Hi kao,

thanks so far.Problem is I have already the strings as I did post above.Now I don't wanna change them back etc.So can I not compare both strings with wsprint API with any pattern etc?So if not then I have to handle and check the entrys manually (Year to hex x2 compare which is higher.If same check next entry of month etc).

greetz

Share this post


Link to post
kao

Yes, you can also scratch your left ear with your right foot. However, it's gonna be terribly uncomfortable. :-)

Share this post


Link to post
cob_258

if the date format was YYYY/MM/DD strcmp would work fine, try to split it (the date) and concatenate it backward (I don't know which language you're using, so I'm not sure if this will help you)

Share this post


Link to post
kao

@cob_258: LCF-AT is hardcore and uses only assembly. :)

@LCF-AT: Something like this could work - but it's a very inefficient and horrible hack that relies on your specific time formatting: http://pastebin.com/UtUDTJLs

  • Like 1

Share this post


Link to post
cob_258

@kao @LCF-AT not sure about this information but maybe setting direction flag to 1 may cause strcmp to work backward, I say this because once this API was crashing when I used STD instruction just before calling it

EDIT : the API is lstrcmp not strcmp (my bad), I tested it under win8.1 x64 and it seems that it has been fixed

Edited by cob_258 (see edit history)

Share this post


Link to post
cob_258

@LCF-AT since your're using asm (and I didn't  code in asm for a long time) I've written this function that compares date (only) in the format you use

DateCompareBackward.rar

  • Like 1

Share this post


Link to post
LCF-AT

Hey guys,

thanks for your help so far so I will check the asm codes you did posted. :) Hey kao,your example code does look almost as mine I tried to build yestersay.Many compare command. :)

Thanks again so far guys and till later.

PS: I also tried to use the time "DateTime.inc" with some functions I found inside like "StringToDateTime" etc but WinASM does show me a external error "unresolved external symbol _StringToDateTime@8" so don't remember anymore how to fix that kind of errors.

greetz

Share this post


Link to post
cob_258

@LCF-AT if you're interested in conversion I've written another version that convert from string to dword than do the comparison, and this function is smaller (93byte) than the previous (110byte)

DateCompareBackward_1.rar

Share this post


Link to post
LCF-AT

Hi guys its me again,

short another question about by sorting stuff.So in the tutorial 31 (see kao post) there I can find a name sort and a filesize sort using String2Dword function in the compare routine.Normaly it works fine but just for files which are not higher than 4 GB etc you know.Now I wanna change this so that all get sortet right by size also if files are higher than 4 GB.Now the question is what I should use now.So the size value string I got like this only in KB (123.123 kb) like in exlorer.Now I thought I should use sscanf API with I64d and then do a double compare of the qwords (first +4 compare and if same compare first dowrd of qwords).So it seems to work but problem is the . in the string.All in all I have to remove the points in the strings and move the part before the string one part to right side.Of course its again very un-handy to do this again and here I wanna ask you whether you got any better solution in your mind which I could use in that case.

greetz

Share this post


Link to post
cob_258

I'm not sure that I understand your problem but there is my idea :

if the size string you get have all the same formate (xxx.xxx Kb) all you need is to compare strings directely with 

mov ecx,size_of_strings ; obtained somehow
mov edi, offset szSize1
mov esi, offset szSize2
repe cmpsb
je @equals
	ja @size1Gsize2
	jmp @size2Gsize1
@equals:
;;;
@sizeo1Gsize2:
;;;
@size2GSize1:
;;;

the only problem with this code is that the strings must be "aligned" (not sure for the word :p) I mean the point is at the same position for both, if it's not the case it's obvious that the string with a point at a bigger offset is greather than the other (i.e xxx.xx > xx.xx)

  • Like 1

Share this post


Link to post
LCF-AT

Hi again and thanks for your help so far.So I think your method isn't working so I need to check the values in the strings I have.Just have a look into your Windows Explorer there you can see the sizes as KB strings.

   27.560 KB
       10 KB
1.258.001 KB

I have same too I need to compare now.So I think there is also any API I could use with that strings and any xy paramters maybe and to check which is higher / lower etc.No idea now.

greetz

Share this post


Link to post
cob_258

I thought that the point is to separate decimals (I got things mixed up, my bad), still you can use the way I posted above, since they have all the same format you can begin comparing the string length (lstrlen, or repne scasb with al =0), the bigger string lenght the larger is the file, if the same use the code above

 

  • Like 1

Share this post


Link to post
LCF-AT

Hi again,

ah ok now I see it and you're right.So now it seems to work fine. :) Thanks again cob_258.

greetz

Share this post


Link to post
cob_258

@LCF-AT you're welcome, glad I could help

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...