YouTube2Text

String Functions (format, gsub, split, etc.) - Roblox Advanced Scripting #23 — Transcript

by BrawlDev · 4,969 words · 643 segments · language en · Watch on YouTube

Full transcript

  1. 0:00oh my God it's a string it's literally a
  2. 0:04string on a base plate okay I'm going to
  3. 0:06be honest I don't really know where I'm
  4. 0:07going with this intro but if you
  5. 0:09couldn't guess from the title of this
  6. 0:10video this Roblox Advanced scripting
  7. 0:12episode is going to cover string
  8. 0:14functions from the string library that
  9. 0:17Roblox has provided to us that we can
  10. 0:19use to read but also modify strings in
  11. 0:22Roblox studio and I'm going to be
  12. 0:24showing you 10 of the most commonly used
  13. 0:26functions from the string library that
  14. 0:28Roblox has for us to offer so with that
  15. 0:30being said let's go ahead and get
  16. 0:31straight into implementing in Roblox
  17. 0:33studio now that we understand it let's
  18. 0:35Implement string functions inside of
  19. 0:36Roblox studio so I quickly whipped up a
  20. 0:39script inside of server script service
  21. 0:40that has two lines one for a variable
  22. 0:43that is set equal to a the string hello
  23. 0:45world and then we're simply just going
  24. 0:46to print that string now we don't need
  25. 0:49to go over what this does it's very
  26. 0:50self-explanatory but I do want to
  27. 0:53incorporate uh some string functions to
  28. 0:56uh our already existing strings so that
  29. 0:58I can show you all the different way
  30. 0:59ways you can manipulate strings um and
  31. 1:02incorporate them in your Roblox game
  32. 1:04starting with the first function which
  33. 1:06is called Len and this is basically
  34. 1:08short for length and this function
  35. 1:10basically counts the length of a string
  36. 1:13and the length of a string is determined
  37. 1:15by the number of characters uh that are
  38. 1:18in a specific string so in this case uh
  39. 1:21this string hello world it has 1 2 3 4 5
  40. 1:246 cuz we're counting the space as a
  41. 1:26character 7 8 9 10 11 12 so it should be
  42. 1:30a length of 12 characters and that is
  43. 1:32essentially what this function should
  44. 1:34return if we use the Len function and
  45. 1:37this is basically what it's going to
  46. 1:38look like so in our print statement
  47. 1:40we're simply just going to start by
  48. 1:41saying string. Len we start with the
  49. 1:45keyword string and then dot Len which is
  50. 1:47the function name and then we're going
  51. 1:49to wrap our and then we're going to wrap
  52. 1:51this in parentheses and put my string as
  53. 1:55a argument for it so if we were to go
  54. 1:57into the game hit test and then hit run
  55. 2:00we should see in the output it should
  56. 2:02say the number 12 because instead of
  57. 2:04printing out the string itself we are
  58. 2:06printing the length of the string which
  59. 2:08is going to be 12 so this is one of the
  60. 2:10easiest and also most useful string
  61. 2:13functions to use in Roblox studio and in
  62. 2:15Roblox studio and I highly recommend you
  63. 2:17use this in your future games the next
  64. 2:20string function is called find and this
  65. 2:22function essentially allows us to locate
  66. 2:25a specific location within a string uh
  67. 2:29to find a specific pattern that we want
  68. 2:31to look for so let's say we were looking
  69. 2:33at this string hello world and we wanted
  70. 2:35to look for just the hello part uh
  71. 2:38basically what would happen is if we
  72. 2:41used this find function it's going to
  73. 2:43return two numbers it's going to return
  74. 2:45the index of where it starts to find
  75. 2:47this word and then the index of where
  76. 2:49this word ends so if you remember how we
  77. 2:52count indices in a string we basically
  78. 2:54start at index one and then we go up
  79. 2:57like we're just counting numbers
  80. 2:58basically um so it's going to start at
  81. 3:01index one with h and then it's going to
  82. 3:04end at index 5 with the O and that is
  83. 3:07essentially what string doind allows us
  84. 3:09to do so instead of string. Len we're
  85. 3:12going to replace this with string. find
  86. 3:14and then it's going to take in two
  87. 3:17arguments the first one is going to be
  88. 3:18the string itself and then the second
  89. 3:20argument is going to be the pattern that
  90. 3:22we're looking for and if you remember
  91. 3:24the pattern is hello which is what we're
  92. 3:26trying to look for so if we go into the
  93. 3:28game now and hit run what should happen
  94. 3:31in the output is it returns back two
  95. 3:33numbers like I said it returns back two
  96. 3:35numbers the first one being the starting
  97. 3:37index of where we start to find this
  98. 3:39pattern and then the end location of
  99. 3:42this pattern that we are looking for and
  100. 3:45we can be more specific about this too
  101. 3:47like if we just wanted to look for were
  102. 3:49like in world then it's going to give us
  103. 3:52the starting and ending index of just
  104. 3:55those um characters inside of the string
  105. 3:59so it starts at uh index 7 and then ends
  106. 4:01at index 9 and so if you really wanted
  107. 4:03to you could make two variables like
  108. 4:05this by saying local start index comma
  109. 4:08end index equals and then we can just
  110. 4:11take string. find cut this paste it into
  111. 4:14here and then you basically now have two
  112. 4:16variables here separately one for the
  113. 4:18starting index and one for the ending
  114. 4:20index and that is essentially how string
  115. 4:22do find works the next function is
  116. 4:24called G sub and this is essentially
  117. 4:27short for Global substitution so what
  118. 4:30this function does is it takes a string
  119. 4:32and then we pass in a pattern that we're
  120. 4:35looking for so if we were to let's say
  121. 4:37look for the word hello if we wanted to
  122. 4:40replace this word with a different word
  123. 4:42then we're going to go through the
  124. 4:43entire string look for this pattern and
  125. 4:45then we're going to replace it and then
  126. 4:47essentially return back a new string
  127. 4:49that has a new string that made the
  128. 4:52changes that we were looking for and I'm
  129. 4:54going to show you what this looks like
  130. 4:56so we're just simply going to say
  131. 4:58string. G sub open and close parentheses
  132. 5:01and then the first thing we're going to
  133. 5:02pass in is the string itself my string
  134. 5:05and then we're going to look for a
  135. 5:06pattern which let's say instead of world
  136. 5:09what if we wanted to change this to
  137. 5:10something different like braev or
  138. 5:12something then we're going to look for
  139. 5:14the pattern which is going to be world
  140. 5:16and then we have to pass in this
  141. 5:18replacement now this replacement can be
  142. 5:20a string it can be a table or it could
  143. 5:22even be another function itself but I'm
  144. 5:24going to show you all three examples the
  145. 5:26first one is just going to be a normal
  146. 5:27string so I'm just going to replace this
  147. 5:30with brev and so what should happen is
  148. 5:32it's going to return the new string
  149. 5:34that's modified but it actually returns
  150. 5:37two values so the first one is going to
  151. 5:41be the new string itself and then the
  152. 5:43second one is going to be the number of
  153. 5:45occurrences that um or the number of
  154. 5:48changes that have happened to the string
  155. 5:50because we might find hello world world
  156. 5:53like this so it'll just change it twice
  157. 5:56instead of once and so that's going to
  158. 5:59keep track of how many times it's been
  159. 6:00recorded it's going to be in the second
  160. 6:02variable so it's we're just going to
  161. 6:03call this one uh num occurences
  162. 6:07equals and then string. G sub so we can
  163. 6:10uh print the new string and we can also
  164. 6:13print the number of occurrences like
  165. 6:17this so if we go into the game hit run
  166. 6:19then what we should see in the output is
  167. 6:21first the new string so it's going to
  168. 6:23say hello braev brev because there's two
  169. 6:27worlds so we changed it both times and
  170. 6:29then it returned the number of
  171. 6:30occurrences that uh have changed with
  172. 6:33the string now if let's say we wanted to
  173. 6:35look for any word and not just a
  174. 6:38specific word uh like if we wanted to
  175. 6:40look for hello world world all that sort
  176. 6:43of stuff like as long as it's spaced out
  177. 6:45by a space and these are all individual
  178. 6:48words that we're trying to look for then
  179. 6:50what we can do is use a special pattern
  180. 6:52that allows us to capture that so I'm
  181. 6:54just going to comment this out I'm going
  182. 6:56to copy this paste it down here instead
  183. 6:59of of having the pattern just be the
  184. 7:01string world what we want to do instead
  185. 7:04is make this a um a word identifier and
  186. 7:07this is essentially what it's going to
  187. 7:08look like we're going to put in a uh
  188. 7:11percent symbol W like w stands for word
  189. 7:14and then we're going to add a plus sign
  190. 7:16indicating that we can have more than
  191. 7:18one word that we look for um I'm going
  192. 7:20to explain in more detail what this
  193. 7:22identifier means but this is essentially
  194. 7:24how you capture uh any word inside of a
  195. 7:27string and we're going to replace
  196. 7:28whatever's inside of here with um this
  197. 7:31with whatever the replacement is on the
  198. 7:32right so if we hit run then everything
  199. 7:35should say braev braev braev uh just
  200. 7:38like that so that is how that works now
  201. 7:41if we let's say wanted to uh make a
  202. 7:44table instead of having a direct
  203. 7:45replacement just be a string we can have
  204. 7:48a dictionary of tables that tell us that
  205. 7:50we want to replace hello with something
  206. 7:51else or if we want to replace world with
  207. 7:54something else then we can use a table
  208. 7:56so I'm going to comment this out and I'm
  209. 7:57going to show you down here um that we
  210. 8:00can indicate any word that's in here but
  211. 8:03we can put a replacement dictionary
  212. 8:05inside of here uh like this so for each
  213. 8:09key uh it's going to be the word that
  214. 8:11we're looking for so in this case we can
  215. 8:13say one example being hello we're going
  216. 8:15to set this equal to uh the the new
  217. 8:20string that we want to replace this with
  218. 8:21so that's going to be the value so
  219. 8:23instead of hello what if we just wanted
  220. 8:24to say uh greetings like this and then
  221. 8:27we'll space this out with a comma and
  222. 8:29then
  223. 8:29we can replace world with uh let's say
  224. 8:32braw Dev instead so now anytime we find
  225. 8:36a word that matches hello we're going to
  226. 8:38replace it with greetings anytime we
  227. 8:40find a word that matches World we're
  228. 8:42going to replace it with balev so now
  229. 8:44let's hit run and then see our new
  230. 8:45output so it should say greetings balev
  231. 8:49brev and it should have been replaced
  232. 8:51three times because we used a uh
  233. 8:53dictionary to allow us to change
  234. 8:55specific words uh in the string here's
  235. 8:58another cool thing we can do
  236. 8:59we can put this in a function that
  237. 9:01basically says uh whatever word we find
  238. 9:04in here then we can put this in a
  239. 9:06function and return a new value based on
  240. 9:09the outcome of this function that um we
  241. 9:11give it I'm going to show you what this
  242. 9:12looks like so I'm going to drop a line
  243. 9:14down here paste this into here and then
  244. 9:17right before it we're going to declare a
  245. 9:18new function we're just going to say
  246. 9:20local function um operation it could
  247. 9:24just be anything really it doesn't
  248. 9:25really matter uh and then we're going to
  249. 9:27pass in a word like this um we're going
  250. 9:31to hit enter like this and then what we
  251. 9:33can do here is basically return a new
  252. 9:35string by taking in the word and then we
  253. 9:37can concatenate this with let's say
  254. 9:39something random we can just say word uh
  255. 9:43I I don't know plus one I'm just like
  256. 9:46thinking of something random off the top
  257. 9:47of my head right now so we're going to
  258. 9:49have the word uh followed by a space and
  259. 9:51then in parenthesis plus one so we're
  260. 9:53just going to return that as the new
  261. 9:55string every single time we pass in a
  262. 9:57new word into this function so for our
  263. 10:00replacement instead of using a table
  264. 10:01we're going to just simply put in the
  265. 10:04operation function and the rest should
  266. 10:06do it for us so now let's hit run and
  267. 10:09then see our output like so uh we should
  268. 10:12see Hello plus one uh world plus one and
  269. 10:15then world plus one again so that is
  270. 10:18another cool thing you can do with G sub
  271. 10:19and I hope this part has um been very
  272. 10:22practical to you so far the next one is
  273. 10:24split and it's actually pretty easy if
  274. 10:26we imagined our string to be like this
  275. 10:29spaced out by three different words but
  276. 10:30we wanted to separate all of these words
  277. 10:33into an an array or in into a table that
  278. 10:37we can use to iterate through all of
  279. 10:39these different words what we can do is
  280. 10:42use the split function that basically
  281. 10:44splits this string into three different
  282. 10:48words inside of a table and then we can
  283. 10:50use that table to iterate through all
  284. 10:52the words so this is basically what it's
  285. 10:53going to look like we're just simply
  286. 10:55going to say local words because we're
  287. 10:57going to return a table equals
  288. 10:59string dosit open and close parenthesis
  289. 11:02we're first going to pass in the string
  290. 11:05and then we're going to pass in a
  291. 11:07separator and this can also be a string
  292. 11:08as well or just a simple character so in
  293. 11:11this case what we want to separate here
  294. 11:13is the space and so this separator is
  295. 11:16going to tell us that every anytime we
  296. 11:18see a space we're going to separate
  297. 11:20whatever was before it into a um entry
  298. 11:24and then we're going to put that into
  299. 11:25the table words like that it's kind of
  300. 11:27strange by default I'm pretty sure
  301. 11:29Roblox has commas as the separator even
  302. 11:33though in a lot of other languages they
  303. 11:35have space as the default so uh if
  304. 11:38you're trying to use space then you need
  305. 11:40to specify space if you want to uh
  306. 11:42separate the words so now that we have
  307. 11:45this we can basically iterate through uh
  308. 11:47every single word that's in the words
  309. 11:50table like this and then that's
  310. 11:54basically that's that's basically all we
  311. 11:56need to do right here so if we hit run
  312. 11:57then what we should see is is that for
  313. 11:59each entry it's going to print out all
  314. 12:01the words that have been separated so we
  315. 12:02have hello and then drops down a line to
  316. 12:05world and then finally world again after
  317. 12:07it was separated the next two functions
  318. 12:09are synonymous with each other and those
  319. 12:11are upper and lower so basically what
  320. 12:16these two functions do is it takes a
  321. 12:18string and then it takes and then it
  322. 12:21changes every single character to be the
  323. 12:23uppercase or lowercase version of that
  324. 12:26character so if we were to basically
  325. 12:29print out uh string. uper in this case
  326. 12:33and then we pass in my string like this
  327. 12:36it's going to take every single
  328. 12:37character and make it uppercase by force
  329. 12:41and then we can basically do the same
  330. 12:42thing down here with uh string. lower
  331. 12:46like this and then if we go into the
  332. 12:47game and then hit run we should see in
  333. 12:49the output that with my string it's
  334. 12:52going to first print out the entire
  335. 12:54string in all uppercase and then for the
  336. 12:56lower it's going to print out every
  337. 12:59single character in the string in
  338. 13:00lowercase I think it's pretty
  339. 13:01self-explanatory I don't need to explain
  340. 13:03too much on this one the next function
  341. 13:05is format and this is actually one of
  342. 13:06the more difficult ones to understand
  343. 13:08and this is something I can make a whole
  344. 13:10video about but I'm not going to go too
  345. 13:12much into detail about it I'm just going
  346. 13:13to show you the basics of using string
  347. 13:15format and how it works so let's say we
  348. 13:18have our string up here with hello world
  349. 13:20and we wanted to reuse this string to
  350. 13:23have a specific format so that if we
  351. 13:25wanted to use the string for a future
  352. 13:27use case or or if we just wanted to use
  353. 13:29a string that's very organized with this
  354. 13:31format that we like to have it with then
  355. 13:34we use the string format function that
  356. 13:37allows us to do that one example of
  357. 13:39using string format is by uh specifying
  358. 13:42one word in here that we want to change
  359. 13:45based on where we uh based on when and
  360. 13:48where we use this in our code so instead
  361. 13:50of world let's say we wanted to replace
  362. 13:52this with um braw Dev or we wanted to
  363. 13:56replace this in a different place with
  364. 13:59Roblox like we want to constantly we
  365. 14:01want to replace whatever this word is
  366. 14:04with a different word but using the same
  367. 14:06format what we can do is replace this
  368. 14:09with a specifier and the type of
  369. 14:11whatever this is inside of here so this
  370. 14:13is basically what it would look like so
  371. 14:15since we don't know what this is yet um
  372. 14:17we can now specify this with braw Dev we
  373. 14:20can even specify this with world and we
  374. 14:22can even specify this with roblocks
  375. 14:24depending on how we use this and this is
  376. 14:25basically how it works down here we can
  377. 14:27say print string
  378. 14:29format open close parenthesis pass in
  379. 14:31the string and then inside of here we
  380. 14:34can pass in whatever we want to replace
  381. 14:35this with we can basically say world and
  382. 14:38we can copy and paste this down here and
  383. 14:40we can replace this with brev and we can
  384. 14:42also replace this with roadblocks so if
  385. 14:45we hit run then we should see all three
  386. 14:48use cases down in the output so we
  387. 14:50should first see world then braev and
  388. 14:52then Roblox so that is one way we can
  389. 14:55use string format and there's definitely
  390. 14:56many other ways we can use this we can
  391. 14:58use this to help uh pad our strings to
  392. 15:01make it look nice by let's say having
  393. 15:03some padded uh space before or after a
  394. 15:05string using Flags uh we can even use um
  395. 15:10width to specify how long we want a
  396. 15:12specific um part in the string to be
  397. 15:15like let's say we had the number 100 but
  398. 15:18we wanted it to be longer than 100 for
  399. 15:21padding reasons like if we want to have
  400. 15:23multiple numbers that had a similar
  401. 15:25padding with two zeros regardless of how
  402. 15:28big or small numbers then we can just
  403. 15:30add some trailing zeros to here um if we
  404. 15:32wanted to give a certain amount of width
  405. 15:36to uh our formatted string like so
  406. 15:38there's a lot of use cases for this but
  407. 15:40I do want you to be aware of the four
  408. 15:43parts that make up a format it's the
  409. 15:45specifier which is indicated by this um
  410. 15:48percentage symbol right here then it's
  411. 15:50going to be the flags the width and then
  412. 15:52the Precision so the specifier
  413. 15:54essentially is this symbol right here
  414. 15:56like I just mentioned and whatever hap
  415. 15:58and and then whatever character we place
  416. 16:00after that that's going to specify the
  417. 16:03type of whatever we we want to insert
  418. 16:05inside of here so the S stands for
  419. 16:07string but if we wanted to let's say
  420. 16:09specify an integer or a number then we
  421. 16:11specify it using d uh or even I in this
  422. 16:14case if we wanted to do a float we would
  423. 16:16specify with f and you kind of get the
  424. 16:17idea with this specifier and this uh
  425. 16:20data type we can basically replace it
  426. 16:22with uh whatever this second argument is
  427. 16:24going to be right here so this float
  428. 16:26could be 10.5 and it's going to be put
  429. 16:29inside of here and you have to make sure
  430. 16:31that you get the right specifier type
  431. 16:33with whatever argument you're trying to
  432. 16:35put inside of these parameters right
  433. 16:37here Flags help us achieve uh certain
  434. 16:40kinds of uh formatting like let's say we
  435. 16:42wanted to add padding to the left side
  436. 16:44then what we can do is basically say uh
  437. 16:47let's say we had a print statement down
  438. 16:48here with string.format like this and
  439. 16:51then let's create our own pattern here
  440. 16:53if we wanted to let's say specify a flag
  441. 16:56of having a bunch of padded space on the
  442. 16:59right side of whatever we put inside of
  443. 17:01here then what we need to do is put down
  444. 17:03a negative sign and then we put down the
  445. 17:06the amount of padding we want to put in
  446. 17:08here so if we let's say wanted 10
  447. 17:10characters after we put in a value
  448. 17:12inside of here so this is going to be
  449. 17:14the padding and then whatever we specify
  450. 17:16inside of here we can let's say this be
  451. 17:18a number then we can put on the right
  452. 17:21side our number which in this case we
  453. 17:23could probably just say 100 I'm just
  454. 17:25going to comment these two parts out
  455. 17:26really quick okay so let me hit run very
  456. 17:28quick ly and then what we should see in
  457. 17:29the output is 100 but you might notice
  458. 17:32that there's all of this white space
  459. 17:34after it because we added a padding to
  460. 17:37it and what's interesting about this as
  461. 17:39well is we can combine multiple Flags
  462. 17:42together like another instance of this
  463. 17:43would be adding zeros to our padding so
  464. 17:47we could get rid of this negative flag
  465. 17:49and instead put a zero to Pad 10 zeros
  466. 17:54to the left of the number that we have
  467. 17:56specified here so if we hit run and then
  468. 17:58what we should see in the bottom is that
  469. 18:00there isn't exactly 10 zeros to the left
  470. 18:03of it but it has a fixed length of 10 uh
  471. 18:07numbers now because uh 100 makes up
  472. 18:09three of them and then the seven zeros
  473. 18:11pad the rest of them to the left side of
  474. 18:14the number and then we have things like
  475. 18:15Precision if let's say we had a decimal
  476. 18:18that we wanted to be in the hundreds or
  477. 18:20the thousands place like this um or if
  478. 18:23we want to have a period specifically
  479. 18:25after the 10 right here then what we can
  480. 18:28do is use uh what we can do is use float
  481. 18:31Point Precision which basically looks
  482. 18:33like this if we had a print statement
  483. 18:35with string. format like this um and
  484. 18:38then we basically had our own formatted
  485. 18:40string like this with a specifier and
  486. 18:43then a DOT uh let's say we want to have
  487. 18:46a number like this to F and then we
  488. 18:50specify the number we have right over
  489. 18:52here to the left side so let's say we
  490. 18:53want it to be 100 essentially What's
  491. 18:56Happening Here is we first have our
  492. 18:57specifier and then we have a period two
  493. 19:00which basically tells us that uh with
  494. 19:02whatever float value that we put inside
  495. 19:05of here uh we want to pad it with a DOT
  496. 19:09and then Pat it with two zeros after we
  497. 19:13give this number to this format so if we
  498. 19:15hit run then we should see in the output
  499. 19:17it shows
  500. 19:19100. because we specified a float Point
  501. 19:22Precision with the dot and the tube with
  502. 19:24also the f um afterwards as well so
  503. 19:27that's another and useful thing you can
  504. 19:29do with string format once again this is
  505. 19:31just a very brief overview of string
  506. 19:33format but I hope this gave you more
  507. 19:35insight into using string format for the
  508. 19:37future the next function is match now
  509. 19:40this is very similar to find that we had
  510. 19:43at the very beginning of this episode so
  511. 19:45this one right here because find
  512. 19:47returned two numbers that basically gave
  513. 19:49us the starting index and the ending
  514. 19:51index of where they found this matching
  515. 19:53pattern but this time this is just
  516. 19:55simply going to return the the value
  517. 19:58itself if it does find it in the string
  518. 20:01so this is all we're going to say we're
  519. 20:02just going to make a print statement
  520. 20:04right here and then we're just going to
  521. 20:05Simply say string. match open and close
  522. 20:08parentheses we're first going to put in
  523. 20:09my string and then whatever is going to
  524. 20:11be on the right side is going to be uh a
  525. 20:13string pattern so if let's say we wanted
  526. 20:15to find World in hello world then what
  527. 20:18it's simply just going to do is return
  528. 20:21that word that pattern that it found in
  529. 20:25the string so if we hit run then what we
  530. 20:27should see in the output is just simply
  531. 20:29world because it found world now if
  532. 20:33let's say we put something that it
  533. 20:34wouldn't be able to find like let's say
  534. 20:36the number uh 103 as a string then it
  535. 20:39should just print out nil because it was
  536. 20:43not able to find it so match basically
  537. 20:45says it either finds the word that it's
  538. 20:47looking for or it just returns nil and
  539. 20:49it's just as simple as that next up we
  540. 20:51have reverse which basically just takes
  541. 20:53the string and then it and then it flips
  542. 20:57the ordering of the uh characters in
  543. 21:00Reverse so if we were to print this out
  544. 21:03say string. reverse and then we pass in
  545. 21:06just one argument which is just going to
  546. 21:08be the string then all that's going to
  547. 21:10happen in the output is it's going to
  548. 21:12print out the same string but in the
  549. 21:15opposite direction so it's going to
  550. 21:18basically just say so it's basically
  551. 21:20just going to print hello world in
  552. 21:21Reverse it's pretty self-explanatory it
  553. 21:23shouldn't be that hard to understand I
  554. 21:24think you get it next function is rep
  555. 21:26and this is short for repeat so
  556. 21:29basically this takes the string and then
  557. 21:31it repeats that string over and over
  558. 21:33again uh for however many times we
  559. 21:35specify it with this function so this is
  560. 21:38basically what it's going to look like
  561. 21:39if we say print open and close
  562. 21:41parentheses string. rep open and close
  563. 21:44parentheses and then we p and then we
  564. 21:46first pass in my string and then at and
  565. 21:49then for the second argument we put down
  566. 21:51a number here so we can say three in
  567. 21:53this case it's going to print hello
  568. 21:55world or no the string is going to to
  569. 21:58say hello world hello world and then
  570. 22:00hello world three times so if we run the
  571. 22:02game and the output the one string
  572. 22:04should just say hello world hello world
  573. 22:07and then hello world so it just simply
  574. 22:08repeats the string that we pass in with
  575. 22:11however many times we specify on the
  576. 22:13right side the last function I'm going
  577. 22:14to introduce is g match which is short
  578. 22:17for Global match and it's as the name
  579. 22:19suggests it's pretty similar to match
  580. 22:21and how if we found a specific string or
  581. 22:24even a specific pattern within a bigger
  582. 22:27string then we would just simply return
  583. 22:30that string itself but with gmch what
  584. 22:32this does is it returns an iterator for
  585. 22:35us to constantly Loop through a uh big
  586. 22:38string to uh return uh the results of
  587. 22:41what we're trying to look for within
  588. 22:42that string it's especially useful if we
  589. 22:45provide a formatted string as the
  590. 22:48pattern and so here's what we can do we
  591. 22:50can essentially write a for Loop that
  592. 22:53can Loop through all of the words inside
  593. 22:55of the string and then we can print it
  594. 22:57out into the output just as a very basic
  595. 22:59example so here's what we're going to
  596. 23:00say we're going to say for word in
  597. 23:04string. g match and then in parentheses
  598. 23:08we're going to pass in our string and
  599. 23:10then our pattern which this is going to
  600. 23:12be a specifier for any word that we find
  601. 23:16inside of here so we're going to use the
  602. 23:19percentage sign W and then we're also
  603. 23:21going to add a plus flag to it so that
  604. 23:24um we know that we're we can retrieve
  605. 23:26any word that's past this so um once we
  606. 23:30do that we can say do and then we can
  607. 23:32simply just say print word and this is a
  608. 23:34very basic example of using gmch so if
  609. 23:37we hit run then what we should see in
  610. 23:38the output is simply just hello world
  611. 23:42without taking into account the um ex
  612. 23:45exclamation point at the very end of it
  613. 23:47because we're trying to catch words
  614. 23:48rather than symbols and with that being
  615. 23:51said that should be the 10 most used
  616. 23:53string functions that the string
  617. 23:55functions library has to offer I hope
  618. 23:56you found this video to be inform ative
  619. 23:58so with that being said I hope you
  620. 23:59understand more about using string
  621. 24:01functions inside of Roblox Studio I'll
  622. 24:03leave a link to the documentation in the
  623. 24:05description of this video if you want to
  624. 24:06take a closer look at it I might make a
  625. 24:08future video on string format as its own
  626. 24:11separate video because it is pretty
  627. 24:13confusing to learn about at first I
  628. 24:15encourage you to use these string
  629. 24:16functions in your Roblox scripts in in
  630. 24:19case you do want to mess around with
  631. 24:21strings because that is something you
  632. 24:23are pretty much going to have to do for
  633. 24:25a lot of the time you are going to be
  634. 24:26developing on Roblox so I hope this
  635. 24:28video serves you well if you want to
  636. 24:30learn more libraries that Roblox has to
  637. 24:32offer that I've covered on this channel
  638. 24:34I encourage you to watch my cortines
  639. 24:36video that I will have a link for you
  640. 24:38right here to watch but with that being
  641. 24:40said I hope you found this video to be
  642. 24:42helpful and I will see you in the next
  643. 24:44episode take care

About this transcript

This page contains the full transcript of String Functions (format, gsub, split, etc.) - Roblox Advanced Scripting #23 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,969 words across 643 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.