Thank you so much. I know it was something very simple but I just couldn't figure it out. Have a good day!
what will it return if there are 2 or more space between 2 words?
Initializing variables here would cost a bit of memory, and you don't really have to do so; it would just be better off not using variables imho.
Also can be done using regex expression. Here is an example using regex extension by @Kevinkun
In the case of these space and double space variables, there is a benefit to the programmer and readers of the code in using well named variables for these text constants.
AI2 has an unfortunate habit of trimming blanks from the end of its text blocks, and not showing the difference between a single blank and an empty text value. For that reason, when I need a single space, I use a well named variable "space" in my blocks, valuing sanity and debug time over execution time and space.
Yes, exactly, that was the reason for the use of a variable, only to clear up the strategy. One can adapt the function to one's favour. It's important to mention for those who didn't use the function "replace" til now that it does only work with the "while" loop.
Interesting, thank you for posting. I didn't know that before. Had just a look to W3Schools/JS
@Joerg_Kowalski, Here it is a general version of program code to remove more than one spaces.
and for word count, you can refer Anke's code block.
With regex expression you only need 4 blocks
To illustrate the similarity between empty text blocks and space blocks, I made a little Blocks Editor game:
Three Block Monte, Find The Space!
Interesting @ABG, while posting second time in this thread, I was thinking that there should be a way to distinguish between empty text box and single space text box to make the program more readable.
Yes, I thought it is concerning to word count only, but at first place I wanted to make it using available blocks only.
@mareshu
Ja, thank you. As we say: "many ways to Rome"; I didn't test your version, but may be that there occurs an error if i = length (global sentence), because segment (lenght plus 1) doesn't exist so that the 2nd comparison in the "If" statement creates that error.
hahahahaha, that's it