Notifications
Clear all
[Closed] string pharsing
Jan 04, 2005 3:26 pm
Hi,
I have a small problem, just need to do this:
“aaabbbccc.123” —> cut after “.” to “aaabbbccc”
Thanks.
4 Replies
1 Reply
Couple of options:
str = "aaabbbccc.123"
substr1 = substring str 1 ((findString str ".")-1)
substr2 = (filterString str ".")[1]
In both cases, it is a good idea to make sure the period “.” actually exists in the string before attempting to truncate.
Like this:
thePos = findString str "."
if thePos != undefined then
substr = substring str 1 (thePos-1)
else
substr = str
Jan 04, 2005 3:26 pm
u cud try this, i cant think any other method right now…
mytext = "aaabbbccc.123"
newtext = ""
for i in 1 to mytext.count while mytext[i] != "." do
(
newtext += mytext[i]
)
print newtext
i hope this helps!
Jan 04, 2005 3:26 pm
If you have a more recent version of Max (R6 and R7 only, I think) you could also do:
trimRight “aaabbbccc.123” “.123”
Personally I’d use fillterString(), subString(), or trimRight() before the loop the first respondent wrote. It’s always better to use the functions MaxScript provides – less chances for bugs, usually faster, and makes your code easier to understand.