string

Discussions about Coding and Scripting
Post Reply
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

string

Post by Rakiayn »

is it possible to check if a string contains a certain part?

example
the string = ''blueredpurple''
i want to see if the string contains ''red''
User avatar
anth
Adept
Posts: 257
Joined: Thu May 13, 2010 2:23 am

Re: string

Post by anth »

Code: Select all

if (InStr(someStr, "red") != -1)
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: string

Post by Feralidragon »

^ What anth said.

I must note however that the code above only makes case-sensitive matches, so it matches "red" but it does not match "RED" for example.
If you want to make it case-insensitive:

Code: Select all

if (InStr(Caps(someStr), Caps("red")) != -1)
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: string

Post by Rakiayn »

thnx guys
if i want to see if a certain part is not in the string, I replace the != with ==?
User avatar
Sp0ngeb0b
Adept
Posts: 376
Joined: Wed Feb 13, 2008 9:16 pm
Location: Cologne
Contact:

Re: string

Post by Sp0ngeb0b »

Yep :)
Website, Forum & UTStats

Image
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
Post Reply