LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find a capital letter in a string.

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.

Find Capital Letters in String.png

 

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

Message 11 of 21
(712 Views)

@Abhilash_Adv wrote:

Find capital Latter, Total no Space in given string input.png

 

 


 

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.

 

altenbach_0-1725808862608.png

 

Message 12 of 21
(708 Views)

I like this:

paul_a_cardinale_0-1725849735583.png

Be sure to right-click on "Search and Replace String" and ensure that "Regular Expression" is checked.

Message 13 of 21
(684 Views)

@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

alexderjuengere_0-1725961051389.png

capitalization.png

 

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..

Message 14 of 21
(645 Views)

@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

alexderjuengere_0-1725961051389.png

capitalization.png

 

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:

 

altenbach_0-1725980204000.png

(And yes, the OP wanted an array of capital letters, which would require some minor changes, of course, e.g. as follows)

 

altenbach_0-1725980869536.png

 

Message 15 of 21
(625 Views)

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!!

 

snip.png

0 Kudos
Message 16 of 21
(591 Views)

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

0 Kudos
Message 17 of 21
(580 Views)

@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".

alexderjuengere_0-1726041799297.png

 

 

0 Kudos
Message 18 of 21
(560 Views)

@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!

 

altenbach_0-1726066067723.png

 

... 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!

 

0 Kudos
Message 19 of 21
(541 Views)

@altenbach wrote:

... and yes, even the very first answer would be a simple solution.

 

find upperletter array strings.png


Let's be clear that this is actually the best solution, because there are more uppercase letters than just A..Z!

 

altenbach_0-1726067851558.png

 

Message 20 of 21
(527 Views)