View Full Version : string pharsing
igor333 01-04-2005, 02:26 PM Hi,
I have a small problem, just need to do this:
"aaabbbccc.123" ---> cut after "." to "aaabbbccc"
Thanks.
|
|
galagast
01-04-2005, 03:15 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!
Hi,
I have a small problem, just need to do this:
"aaabbbccc.123" ---> cut after "." to "aaabbbccc"
Thanks.
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
igor333
01-04-2005, 06:21 PM
Hi,
Thanks :)
Jeff_hanna
01-05-2005, 01:52 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.
CGTalk Moderation
01-20-2006, 08:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.