09-08-2024 10:19 AM
I'm unsure why @Abhilash_Adv felt compelled to add another reply to an eight-year-old post about finding capital letters in a string, but in my humble opinion, most of the proposed "solutions" missed some simplifications in asking "questions" about string elements (single characters). If you convert the string to an Array of U8s, doing arithmetic (like comparisons) becomes much simpler and easier to understand.
Should you want to know the positions of, say, the Spaces or the Upper Case letters, bring the For Loop Index out through a Conditional (Array) tunnel with either the "Is Space" or the "Is Upper Case" condition wired to it.
Bob Schor
09-08-2024 10:24 AM - edited 09-08-2024 10:00 PM
@Abhilash_Adv wrote:
While a good exercise to practice coding skills, this seems overly complicated and does not answer the ancient question (from 2016!) of creating a new array with only the capital letters and where the input is an array of strings.
Here's how your thing could be done easier (if you really want to see all letters and a boolean array indicating capital letters and count spaces.). To only answer the original question, most of the code can be omitted.
09-08-2024 09:43 PM
I like this:
Be sure to right-click on "Search and Replace String" and ensure that "Regular Expression" is checked.
09-10-2024 04:47 AM
@ponorac92 wrote:
Hello, I have 10 strings and I need to search every sting for a capital letter. If there is a capital letter in a string I need to put the string in an array of strings. I don't know how to separate a string with a capital letter in it. If there is no capital letter than the string is skipped. I tried using the Match Pattern function and it didn't help. Thanks in advance.
[...]
I used [A-Z]+
use [A-Z]+ with "match regular expression" instead of "match pattern"and conditional auto-index the whole matches as an array of strings
offset past match will be -1 if there is no capital in the input entry and furthermore the while loop will execute 0 times if you check {offset past match}<0 and use that to stop the while loop..
09-10-2024 10:02 AM - edited 09-10-2024 01:49 PM
@alexderjuengere wrote:
@ponorac92 wrote:
Hello, I have 10 strings and I need to search every sting for a capital letter. If there is a capital letter in a string I need to put the string in an array of strings. I don't know how to separate a string with a capital letter in it. If there is no capital letter than the string is skipped. I tried using the Match Pattern function and it didn't help. Thanks in advance.
[...]
I used [A-Z]+
use [A-Z]+ with "match regular expression" instead of "match pattern"and conditional auto-index the whole matches as an array of strings
offset past match will be -1 if there is no capital in the input entry and furthermore the while loop will execute 0 times if you check {offset past match}<0 and use that to stop the while loop..
You seem to create an array of string where each element is a consecutive stretch of capital letters. It is not obvious if that's what the OP wanted. Also, your "# of C" seems incorrect.
Also note that the use of REGEX will have a huge performance impact. Here's how my code would fit into your input:
(And yes, the OP wanted an array of capital letters, which would require some minor changes, of course, e.g. as follows)
09-10-2024 04:57 PM
Another way, probably not as fast or efficient, but maybe easier to see functionality. (Concatenating a large array would be slow.) In Range and Coerce works with characters!!
09-10-2024 09:48 PM
If you scroll to the top of the second page of this Post, you'll find my suggestion for finding Capital Letters or Space (and it should be obvious how to find digits (0..9) or any other symbol/character. Note I tried to make code that was succinct, "obvious" (I use "A" instead of 65, the decimal value for the ASCII code for A).
Bob Schor
09-11-2024 03:03 AM - edited 09-11-2024 03:04 AM
@altenbach wrote:
Also, your "# of C" seems incorrect.
you need to read that "[A-Z]+ is found 7 times in the index 0 input string".
09-11-2024 09:49 AM - edited 09-11-2024 09:53 AM
@ponorac92 wrote:
Hello, I have 10 strings and I need to search every sting for a capital letter. If there is a capital letter in a string I need to put the string in an array of strings. I don't know how to separate a string with a capital letter in it. If there is no capital letter than the string is skipped. I tried using the Match Pattern function and it didn't help. Thanks in advance.
Why don't we go to the very first posts (from 2016!!) and look at the actual question instead of going on a snipe hunt based on weird and random "solutions" posted later.
SO: We have an array of 10 strings and only want to keep the array elements that contain a capital letter. Simple enough!
... and yes, even the very first answer would be a simple solution.
I typically try to avoid regex at all costs. They are inefficient and hard to read and turn even me into a dyslexic. No fun!
09-11-2024 10:19 AM
@altenbach wrote:
... and yes, even the very first answer would be a simple solution.
![]()
Let's be clear that this is actually the best solution, because there are more uppercase letters than just A..Z!