Board index FlightGear Development Nasal

Is there Nasal command that checks if var contain word?  Topic is solved

Nasal is the scripting language of FlightGear.

Is there Nasal command that checks if var contain word?

Postby SP-NTX » Wed May 18, 2022 7:03 pm

Hello, im developing addon, and i have to check if the variable contain word.
i have variable 'x', and it contains, lets say, "abc", and i need to check if variable 'x' contains "bc". is it possible in nasal?
Freedom can be frightening if you've never felt it
User avatar
SP-NTX
 
Posts: 212
Joined: Wed Mar 18, 2020 12:14 pm
Location: Western Poland
Callsign: SP-NTX
Version: 2020.4.0
OS: Windows 11

Re: Is there Nasal command that checks if var contain word?

Postby wkitty42 » Wed May 18, 2022 7:32 pm

https://wiki.flightgear.org/Nasal_library#substr.28.29
there's a lot of functions listed on that page, too...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Is there Nasal command that checks if var contain word?  

Postby TheEagle » Wed May 18, 2022 9:10 pm

@wkitty: I think you got the author wrong - he doesn't want to extract a string from a known start and end / length of another string, but he wants to check if a string contains another string ! ;)

@SP-NTX: You could try the builtin find() instead: https://wiki.flightgear.org/Nasal_library#find.28.29
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Is there Nasal command that checks if var contain word?

Postby TheEagle » Wed May 18, 2022 9:13 pm

Or string.String.find_first_of (no docs for that ! :( )
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3411
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Is there Nasal command that checks if var contain word?

Postby wkitty42 » Thu May 19, 2022 12:14 pm

TheEagle wrote in Wed May 18, 2022 9:10 pm:@wkitty: I think you got the author wrong - he doesn't want to extract a string from a known start and end / length of another string, but he wants to check if a string contains another string ! ;)

if there is not already a function for that, one can easily use the one i pointed to to create their own "contains" function ;)

TheEagle wrote in Wed May 18, 2022 9:10 pm:@SP-NTX: You could try the builtin find() instead: https://wiki.flightgear.org/Nasal_library#find.28.29

that might work, too...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Is there Nasal command that checks if var contain word?

Postby Hooray » Sat May 21, 2022 8:09 pm

Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests