Page 1 of 2

Letter-cases

Posted: September 3rd, 2018, 12:08 pm
by arkagwa
Dear developers

The current feature allows two cases for letters; lower letters and upper/capital letters. Sometimes the variable captures three names or two words where you need the initials with capital letters, example Andrew Raphael,....Letters A and R (initials) are capital. This feature is missing

If there is alternative solution kindly help, i find it difficult for data entrants switching cases in keyboard :( :(

Good evening

Re: Letter-cases

Posted: September 4th, 2018, 6:27 am
by josh
Why not just tell the enumerators to use all lower case or all upper case? You can convert to mixed in case in logic if you really need it although in many cases it is not needed. To convert to mixed case just have a loop through the string and each time you find a space you capitalize the next letter.

Re: Letter-cases

Posted: January 8th, 2019, 12:55 am
by arkagwa
Dear Josh

Can you assist me with the code for looping the string to capitalize every first letter.......please i would appreciate very much :) :)

Re: Letter-cases

Posted: January 8th, 2019, 6:10 am
by josh
Try Googling "capitalize first character of each word in string". That will show you some examples in other programming languages that you can adapt to CSPro.

Re: Letter-cases

Posted: January 11th, 2019, 2:41 pm
by htuser
Hi Josh,
I find this code for the same purpose:

Code: Select all

#include <stdio.h>
#define MAX 100

int main()
{
	char str[MAX]={0};	
	int i;
	
	//input string
	printf("Enter a string: ");
	scanf("%[^\n]s",str); //read string with spaces
	
	//capitalize first character of words
	for(i=0; str[i]!='\0'; i++)
	{
		//check first character is lowercase alphabet
		if(i==0)
		{
			if((str[i]>='a' && str[i]<='z'))
				str[i]=str[i]-32; //subtract 32 to make it capital
			continue; //continue to the loop
		}
		if(str[i]==' ')//check space
		{
			//if space is found, check next character
			++i;
			//check next character is lowercase alphabet
			if(str[i]>='a' && str[i]<='z')
			{
				str[i]=str[i]-32; //subtract 32 to make it capital
				continue; //continue to the loop
			}
		}
		else
		{
			//all other uppercase characters should be in lowercase
			if(str[i]>='A' && str[i]<='Z')
				str[i]=str[i]+32; //subtract 32 to make it small/lowercase
		}
	}
	
	printf("Capitalize string is: %s\n",str);
	
	return 0;
}
And it seem difficult to port it to Cspro Programming Language... I can't "translate"
#define MAX 100
scanf("%[^\n]s",str); //read string with spaces
char str[MAX]={0};
str!='\0';


Please can you help us?

In the future when we can use C/C++ functions/methods/classes inside Cspro Logic, this will open an univers for Csprousers.

Thanks in advance!

Re: Letter-cases

Posted: January 11th, 2019, 5:04 pm
by josh
You don't need the scanf part. That part is reading the string that user types in. The important part starts from the for loop.

Re: Letter-cases

Posted: January 11th, 2019, 10:55 pm
by htuser
Hi Josh,
I'm trying to port this code and here's the results...with errors...
Please, can you help me to correct!

Thanks in advance,
CapitalizeString.zip
(2.65 KiB) Downloaded 325 times

Re: Letter-cases

Posted: January 12th, 2019, 3:29 pm
by Gregory Martin
Your code does some things it doesn't need to like use \0, which is not needed in CSPro. You can write this logic pretty simply using CSPro functions:
function string capitalizeEachWord(string text)

    numeric next_non_blank_letter_should_be_capitalized = 1;

    do numeric ctr = 1 while ctr <= length(text)

        string this_letter = text[ctr:1];

        if this_letter = " " then
            next_non_blank_letter_should_be_capitalized = 1;

        elseif next_non_blank_letter_should_be_capitalized = 1 then
            text[ctr:1] = toupper(this_letter);
            next_non_blank_letter_should_be_capitalized = 0;

        else
            text[ctr:1] = tolower(this_letter);

        endif;

    enddo;

    capitalizeEachWord = text;

end;

Re: Letter-cases

Posted: January 13th, 2019, 2:49 pm
by htuser
Thank you Greg. Since Cspro have powerful functions, i had to think in Cspro, not trying to "translate".
Best Regards,

Re: Letter-cases

Posted: January 19th, 2019, 1:49 pm
by arkagwa
Does not work for me ...keep asking for ; operator
Is word "text" a syntax or used as variable??