LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help to find the internal consonants in a string.

Solved!
Go to solution

Hello. I'm trying to make a program that will give an ID once you enter your data, problem here it's I need to find the first internal consonants of the surname and name, but I'm really having trouble with it. I already tried to do it with a match pattern, so it'll give all the consonants from the string and then I tried to use a subset string to grab the letter from a given position, but problem here it's when the name starts with a consonant, it will show the first one instead of the internal one. I'm really lost at this one. This is what I've accomplished so far.

ACMontez_0-1693113631330.png

 

0 Kudos
Message 1 of 18
(1,642 Views)

Your code does do a considerable part of the work and could be modified relatively simply to find the first "internal" consonant (for instance, by searching the original string for the vowels and seeing if the first match is at index zero), but it also has a bunch of issues, some more serious than others:

  1. You're forcing everything to be in capital letters, which may or may not be an issue.
  2. You're making an assumption on the content of the name by searching for vowels. What if the name contains other characters (you can go wild, but at least ' is quite likely).
  3. Is a consonant at the end considered "internal"?
  4. What happens if the name doesn't have consonants?

There are probably others, too.

 

Your code doesn't actually show a Match Pattern function, unlike your description. If you did use a Match Pattern, you would probably find it easier (with something like [B-Db-dF-Hf-h], etc.).

 

It also helps to include actual code with good default values for testing as well as what you expect to see and what you actually see and try to backsave it to earlier versions of LV


___________________
Try to take over the world!
0 Kudos
Message 2 of 18
(1,622 Views)

In addition to the above comments that you should read carefully:

 


@ACMontez wrote:

Hello. I'm trying to make a program that will give an ID once you enter your data, problem here it's I need to find the first internal consonants of the surname and name, but I'm really having trouble with it. I already tried to do it with a match pattern, so it'll give all the consonants from the string and then I tried to use a subset string to grab the letter from a given position, but problem here it's when the name starts with a consonant, it will show the first one instead of the internal one. I'm really lost at this one. This is what I've accomplished so far.


  • What is the difference between the various items the user enters ("data", "surname" and "name")
  • So far you are processing the "surname" and find a "consonant" (defined as "not a vowel", which is fragile. For example there are names that contain a dash, which would count as consonant)
  • Now sure why you first find all consonants. Way too much work! All you really need is find the first (if one exists) and stop processing right there.
  • It would seem easy to trim the first letter to process only "internal" characters?
  • How do you calculate an ID from data/surname/lname. Shouldn't an ID be unique? I can think of situations where several different names give the same ID.

Please attach a simplified version of your code containing all data entry fields. Make sure the string controls are set to "limit to single line". Fill all controls with default data and tell us what ID you would expect for correctly working code. Make sure the surname starts with a consonant to properly test that scenario.

0 Kudos
Message 3 of 18
(1,572 Views)

I'm going to tell what I'm trying to get here, so maybe that will cover all your questions. 

 

What I'm trying to replicate it's to obtain the CURP, which it's a unique identification code used in Mexico to keep track of individuals for various administrative and official purposes. Like the Social Security Number in the US. The CURP it's a 18-character alphanumeric code that is generated based on full name, date of birth, gender, and place of birth.

 

The last three letters are obtained from the name and the surname, using the internal consonants from it. For example, if someone it's called James Jones, the first internal consonants will be M and N, but if the name would be something like Andrew Anderson, the first internal consonants, in both cases would be an N, which it's basically what I'm trying to achieve.

 

That's why I'm forcing it to be all capital letters, because that's how the CURP works as well. Hope this helps. 

0 Kudos
Message 4 of 18
(1,547 Views)

Hi AC,

 


@ACMontez wrote:

The last three letters are obtained from the name and the surname, using the internal consonants from it. For example, if someone it's called James Jones, the first internal consonants will be M and N, but if the name would be something like Andrew Anderson, the first internal consonants, in both cases would be an N, which it's basically what I'm trying to achieve.


What is the 3rd char?

 

To find "internal" consonants:

  1. Get a word (without whitespaces).
    Bonus question: Are names from 2 words with a hyphen in between (like German Karl-Heinz) considered one or two words?
  2. Strip the first char from the word to get rid of leading consonants. String the last char too, when required…
  3. Replace all vocals by empty strings.

Now you have the "internal consonants" of the word…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 18
(1,528 Views)

I'd read this first (same class?):

Solved: write a character string and find the number of vowels in it - NI Community

 

If you set the search and replace string function to match regular expressions (right click it), you can be much more expressive in your search.

0 Kudos
Message 6 of 18
(1,507 Views)

1. Names with 2 words, use the second name in orden to get the consonant from It. 

2. How can I do such thing? I already got the first letter from the word, but it's a there a function to delete It or change It from some other caracter? 

0 Kudos
Message 7 of 18
(1,475 Views)

String Subset will let you strip the first letter:Example_VI.png

0 Kudos
Message 8 of 18
(1,468 Views)

@ACMontez wrote:

1. Names with 2 words, use the second name in orden to get the consonant from It. How can I do such thing?

Either split up functionality (get all words, process words individually) or come up with a clever reg.ex. and execute it until there are no more matches.

 

@ACMontez wrote:

2.I already got the first letter from the word,  


If you post what you have, we could actually reflex on that...

 

@ACMontez wrote:

but it's a there a function to delete It or change It from some other caracter? 


Replace Substring...

Search And Replace String...

Match Pattern Expression and a Concatenate String... 

Match Regular Expression and a Concatenate String... 

2X Search/Split String and a Concatenate String...

2X Strings Subset and a Concatenate String...

Infinite combinations of most string functions allow doing this.

 

I'm not sure why you'd want to replace strings if your goal is to find consonants.

 

Post what you have.

0 Kudos
Message 9 of 18
(1,447 Views)
Solution
Accepted by topic author ACMontez

I haven't seen a solution yet, this is one way:

Find internal consonant.png

Message 10 of 18
(1,406 Views)