Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to find numbers through a script's source (using plugins)?

Asked by
trecept 367 Moderation Voter
6 years ago

I'm creating a plugin that edits scripts for me, and I was wondering how to find out if a number is a string or an actual number? (e.g "2" or 2) Whenever I use typeof() it returns string only for the source, how do I check if the number is part of a string or not?

0
hmm, maybe use tonumber() saSlol2436 716 — 6y

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Given a string you must find numbers in, you can use string patterns. Specifically, you can use the %d+ pattern, which matches digits with the %d character class, and one or more of them with the + quantifier.

To check if there is a string, we can use string.find(string, "%d+").

Helpful resources:

Roblox Wiki entry for string patterns

string.gsub()

string.match()

string.gmatch()

string.find()

Ad

Answer this question