Home Hex Edit Home Page
Hex Edit Features Hex Edit Features
Button Testimonials
Button Screen Shots
Button Downloads
Button Forums Home
Button HexEdit FAQ
Button Known Bugs
about help privacy register
Forums
Search Members Help

» Welcome Guest
[ Log In :: Register ]

 

[ Track This Topic :: Email This Topic :: Print this topic ]

reply to topic new topic new poll
Topic: splitting strings in a template< Next Oldest | Next Newest >
 Post Number: 1
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Mar. 07 2011,09:47  Skip to the next post in this topic. Ignore posts   QUOTE

if I could just get something that works like

CODE
Python:

string_list = 'PlyPikachu5K_Share_matanim_joint'
print string_list.split('_')

>>> [ 'PlyPikachu5K' , 'Share' , 'matanim' , 'joint' ]


Template:
using ' FOR -> STRUCT -> IF' to compair values like 'joint'
(put the "split" function in the FOR on the string var)

I know it wouldn't be "split", but what would it be??


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 2
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Mar. 08 2011,10:37 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

what I need to do in the template is something like:

CODE
string_list = 'PlyPikachu5K_Share_matanim_joint'

if string_list.split('_')[1] == 'Share': #split the string and compair index[1] to 'Share'
   if string_list.split('_')[2] == 'joint': #split the string and compair index[2] to 'joint'
       JOBJ(rootnode_offset) #use the JOBJ structure on the rootnode offset (to position in data block)
   else: pass #skip
elif string_list.split('_')[1] == 'joint': #split the string and compair index[1] to 'joint'
   JOBJ(rootnode_offset) #use the JOBJ structure on the rootnode offset (to position in data block)
else: pass


I need to do that in my template


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 3
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Mar. 17 2011,12:55 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

so no-one has anything on this :/

--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 4
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Mar. 25 2011,07:35 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

ah...
I forgot all about the string terminator >.<

so I can easily set that to terminate at '0x5F' or '_'
and repete the process in a FOR
and there would be my list :P

EDIT:
well, that didn't work out >_>

comon...
I just need to test for "joint" in the string
is it really that hard that it takes weeks to answer D:<

I've got 2 communities waiting on me for this,
so I have quite a valad reason to be complaining now >:(


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 5
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Mar. 31 2011,06:21 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

Sorry, I don't know how I missed seeing this.

If you want to search for a string within a string you can use strstr().


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 6
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Mar. 31 2011,07:20 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

hmm...
that works,
quite well actually,

but not for everything

after spitting the string at every '_',
str[0] would be the char's name...
eg: PlyPikachu5K

everything else labled in that really is of only interest to the user...
type: Ply (player)
name: Pikachu
am unsure of what the '5K' means, or is for

str[1] would be either be 'Share' or another def type

str[2] (if str[1] is 'Share') would be particularly 'joint' or 'matanim'
(there's other possible types)

so yea,
any good function for splitting a string?? <:/

EDIT:
thanx for replying btw...
kinda was starting to think this thread was a useless attempt... heh


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 7
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Apr. 04 2011,04:09 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

There is currently no string splitting function in HexEdit, since the string functions are sort of based on C string functions (but I didn't do strtok as it's pretty awful).

What I could do in the next version is add a function like:

 arr = strsplit("_", "aa_bbb_c");

which would produce an array with 3 elements: arr[0]="aa", arr[1]="bbb", arr[2]="c"

But in the meantime you can use strchr and strleft to manually split a string.  Something like:

CODE

EVAL expr="pos = strchr(str, '_')"
FOR stop_if="pos < 0"
 EVAL expr="sub = left(str, pos)"
 EVAL expr="str = right(str, pos+1)"
 EVAL expr="pos = strchr(str)"
ENDFOR


This searches for the 1st underscore and stores its location in the variable "pos" (-1 if not found).  It then uses that to repeatedly slice off the sub string into "sub" while keeping the rest of the string in "str"

Note that it is very easy to test the behavior of string functions in the calculator.

[I'm not sure this is the exact template XML but it's easier to use the template dialogs anyway.]


Edited by andrew on Apr. 04 2011,04:51

--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 8
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Apr. 04 2011,07:47 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

interesting
I'll be sure to  try that :)

and yea, that'd be a useful thing to add

unfortunatly my understanding of the EVAL types is drastically low :(
I'll learn as time passes...
sry if I'm inconveinencing you at all.

anyways,
thanx for the help :)


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 9
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Apr. 06 2011,08:33 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

well, I have to mod your code, but I'll see what I can do...

errors:
EVAL expr="str = right(str, pos+1)" "expected a variable to the left of the equal sign"
EVAL expr="pos = strchr(str)" "expected a comma ..."

FOR enters an infinte loop and continually lists the first string.


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 10
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Apr. 08 2011,17:45 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

I wrote the template code off the top of my head which is why I said "Something like".  I'll try to get something more accurate for you.

> sry if I'm inconveinencing you at all.

No problems.  I'm just sorry that I don't get time to check these forums more often. :(

It's great that someone is getting real use out of the templates as I put a huge amount of work into implementing them.  I know that a lot of people are using templates for very many different purposes but I don't get a lot of detailed feedback.  I'm very happy to add stuff to the template system to make it easier to create and use them.  I haven't done much with the template handling for a few years as nobody has asked for anything recently.


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 11
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Apr. 08 2011,20:00 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

meh... alright...
on that note, I havn't really had much success,
other than creating more errors... heh

I see...
you must only be on like once a month or something... :/

well...
be glad you ran into me :)
any ideas I have I will gladly submit :D

like this one:
010's template manager lets you edit the code directly,
then tests it when you tell it to.
it autosyncs by default, but as you can see in my other thread,
the tree view is much different (I like HexEdit's tree view better) :)

but yea,
the idea is an XML manager that allows testing of the code when you tell it to
(should have a tab that shows above or below the hex window when the template is loaded)

yeh...
I know it'll take a while to do...
coding is a hard thing -_-
heh


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 12
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Apr. 12 2011,17:34 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

> I havn't really had much success...

If you are only using HexEdit 3.0 then what I said above won't work.  You can't have a FOR just containing only EVALs.


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 13
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Apr. 12 2011,17:45 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

Here is a template that I whipped up that demonstrates how to split a string.  Note that this may not work on HexEdit 3.0 since you can't just have an EVAL within a FOR.  (But probably would just need a change to the DTD file to get it to work).

I recommend downloading the free HexEdit 4.0 beta and using that.

Also I had to create this using a text editor as HexEdit's built-in editor would not let me create a FOR containing just an EVAL.  (I'll have to fix that!)

CODE

<?xml version="1.0"?>
<!DOCTYPE binary_file_format SYSTEM "BinaryFileFormat.dtd">
<binary_file_format name="Split">
   <eval expr="str=&quot;abc_d__ef&quot;" />
   
   <eval expr="pos = strchr(str, '_')" />
   <eval expr="ii = 0" />
   <for name = "split" stop_test="pos &lt; 0">
       <eval expr="sub[ii]=left(str, pos), str=mid(str, pos+1), pos=strchr(str, '_'), ii=ii+1" />
   </for>
   <eval expr="sub[ii]=str" />
   
   <eval expr="ii = 0" />
   <for name="result" stop_test="!defined(sub[ii])">
       <eval expr="sub[ii++]" display_result="true" />
   </for>
</binary_file_format>


The first line sets up a test string.  The middle six lines do the split that you want.  The last 4 lines check the output.

If you have any questions get back to me.


Edited by andrew on Apr. 12 2011,17:49

--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 14
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Apr. 12 2011,19:16 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

that's ok :)

I'll get 4.0 a little later...
(don't feel like installing any new programs for a while)...
^still need to re-install FL stucio XD

anyways...
about the template data...

I can just simply add a "tmp" data with a length of 0
it's a workaround I've been used to using... heh

anyways... thanx for the help :)
hopefully I'll be able to add another model format to my converter now :D


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 15
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: May 14 2011,22:40 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

well, it's been a while...
but I've finally gotten back to this

I got 2 errors that're preventing this thing from working properly...
but, it does work ;)

the errors:
<for name="result" stop_test="!defined(sub[ii])"> (expected closing parenthese)
<eval expr="sub[ii++]" display_result="true" /> (expected a number after +)

would you like me to send my template to you??

I kinda need 3.0 as it's kinda hard to UD a community... heh

if you need a file to use, just rip it from Melee with GC-Tool or Dolphin
I'm working on Pl****.dat files

you can easily get the resources (except for Dolphin) from my old blog:
http://smashbrosfiles.blogspot.com

but that's only if you want to...
I don't wanna infringe upon your work and what not with even more work ^_^


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 16
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: May 17 2011,06:58 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

There are 2 problems: defined() does not work for a variable in 3.0, and ++ operator does not work in 3.0.  You need to use the latest shareware version (3.6) or the beta of the free 4.0 version.  Sorry.

If you want to give your template to a "community" I suggest you get them to try the 4.0 beta.  It's free, no known bugs, and many new features. :)


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 17
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: May 17 2011,13:25 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

I see...

they should take well to that with it being freeware :D

btw... it's 2 communities
1: the Brawl hacking community
2: the Melee hacking community

I HATE FAME!
No I will not do a hack request!
SHUTUP PEOPLE!!!

lol sry XD

but yea... I'll do my best to UD them :)

EDIT:
is there any extra DLL's I should include??


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 18
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: May 18 2011,19:10 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

> is there any extra DLL's I should include??

I believe the download includes all required DLLs.  It uses MFC10 but that should be included.


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 19
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: May 19 2011,16:44 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

KK thanx :)

--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 20
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Jan. 04 2012,18:54 Skip to the previous post in this topic.  Ignore posts   QUOTE

I've found a better way using only 2 expressions and a for
(5 expressions if you split the vars)

anyways...
data: str

expr: I=0, S=str+"_"
for: stop: strchr(S,"_")<0
  expr: L[I]=left(S,strchr(S,"_")), S=mid(S,strchr(S,"_")+1), I=I+1

if L[2]=="joint"


I've decided to hit up the DAT template while taking a break from my MDL0 template :3

so I'm going through and trying to fix up the code and decipher more structures ^_^


--------------
Offline
Top of Page Profile Contact Info WEB 
19 replies since Mar. 07 2011,09:47 < Next Oldest | Next Newest >

[ Track This Topic :: Email This Topic :: Print this topic ]


 
reply to topic new topic new poll

» Quick Reply splitting strings in a template
iB Code Buttons
You are posting as:

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code