Lua string fscanf3/11/2023 ![]() Live Demo function mysplit (inputstr, sep)įor str in string. The above example works fine for simple patterns but when we want to make use of a regular expression and the case that we can have a default pattern with which to split, we can consider a more elegant example. Exampleįor i in string.gmatch(example, "%S+") do In Lua, there is no split function that is present inside the standard library but we can make use of other functions to do the work that normally a split function would do.Ī very simple example of a split function in Lua is to make use of the gmatch() function and then pass a pattern which we want to separate the string upon. Splitting a string is the process in which we pass a regular expression or pattern with which one can split a given string into different parts. The string.sub () function takes three arguments in general, the first argument being the name of the string from which we want to extract a piece, the second argument is the i-th index or say, the starting index of the string piece that we want, and the third and the last argument is the j-th index of the last index of the string piece we want.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |