Jump to content

How to evaluate an integer value as an integer in a string value?


Recommended Posts

Hi,

The title is not very clear but I have a string attribute where I want to modify its values by using basic arithmetic. The string attribute looks like this:


attribute name = mypath
attribute value = "C:/Textures/bump"
[/CODE]

I want to replace "bump" with "disp", and add 1, 2, 3 to it as a suffix with ".jpg":

[CODE]
"C:/Textures/disp1.jpg"
"C:/Textures/disp2.jpg" (next attribute)
"C:/Textures/disp3.jpg" (next attribute)
[/CODE]

I tried this but the number 1 is added as a string, and I don't know how to force it to be evaulated as an integer:

[CODE]`strreplace($MYPATH, "bump", "disp" + ($PT % 3) + 1 + ".jpg")`[/CODE]

The modulo returns, 0, 1, and 2 so I need to add 1 to it, but it ends up as 01, 11, 21 due to string concatenation.

Any idea how to evaluate this as an integer?

Thanks :)

Edited by magneto
Link to comment
Share on other sites

Guest mantragora

For example you can add () around ($PT % 3) + 1

`strreplace($MYPATH, "bump", "disp" + (($PT % 3) + 1) + ".jpg")`

so it gets evaluated as one expression first.

  • 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...