Jump to content

Chop a string into an array in VEX


alr77

Recommended Posts

Dear all,

Good Evening,

 

So, i was digging into the VEX functions "string" section.

And i didn't found any clue to chop a string into an array.

string myString = "1234Abc";

The goal will be to get this below :

string arrayFromString[] = {"1","2","3","4","A","b","c"};

 

As well in python it is "native" :

myString = "1234Abc"

myString[0] would be "1" etc etc....

But to use it in a wrangle i need VEX ....If anybody has a clue :). It will be 100% Welcome, as it could be a very simple way to chop and bytecrush long floating numbers.

Might it be a NOOB question and i apologize already for that.

 

Thank you a lot,

And all the best to everybody with Houdini !!!

 

alr + + +

 

Edited by alr77
Link to comment
Share on other sites

Ouupsss....

Thousand apologies......

I tried :

string myString = "myString";

printf("%s",myString[0]);

 

and it worked..... it printed "m".

so if anybody as me primarily thought a built-in method was required to do this. it is not the case. It is native as in Python.

Good evening, and sorry !

Houdini it is so great.

alr + + +

 

Link to comment
Share on other sites

So...sorry for the "OUPS post just before".

If some are curious about the result of "my crushing decimals string approach".

Please find the VEX below : Plug any geo, create the slider decimalsTrim and test.

float floatCrushing(float myFloat; int decimal)
{
    //VAR INIT:
    float crushedFloatValue = -9999;
    string crushedStringValue = "";
    
    //CRUSHING :
    string stringizeMyFloat = sprintf("%s",myFloat);
    int match_science_notation = match("*e-*", stringizeMyFloat);
    
    if(!match_science_notation)
    {
        //CRUSH THE STRING VALUE :
        int byteSize = strlen(stringizeMyFloat);        
            for(int byte=0; byte < byteSize; byte++)
            {
                crushedStringValue += stringizeMyFloat[byte];
                    if(stringizeMyFloat[byte] == ".")
                        byteSize = byte + 1 + decimal;    
            }
    
        crushedFloatValue = atof(crushedStringValue);
    }
    else
    {    
        //KEEP CURRENT VALUE :
        crushedFloatValue = atof(stringizeMyFloat);    
    }
    
    return crushedFloatValue;
}

 

//TEST ON point "P" :
vector anyVector = {0,0,0};
for(int chan = 0; chan < 3; ++chan)
    anyVector[chan] = floatCrushing(@P[chan], chi("decimalsTrim"));
    
@P = anyVector;

 

 

The goal was to start from High definied geo to harsh geo in a "minecraft" way or 80's CGI.

Here normal Geo

6084b03035445_Screenshot2021-04-25at01_53_13.png.6e3ba4d2437035e1139fd7a26a864b99.png

Here one decimal Geo.

6084b0ad5963a_Screenshot2021-04-25at01_53_36.png.92f928de88191c72da1f1a2b835e525f.png

As well add a fuse at the end.

Change the code to make it works on single float or else, you can also "crush" any Cd vector or noise or else.

And sorry for my "OUPS question ^^".

 

If you find any use for you, it is cool. (on my side i needed it hehe^^).

Good evening,

Thank you,

bests,

 

alr + + +

 

Edited by alr77
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...