Letter-cases
Letter-cases
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
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
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
Dear Josh
Can you assist me with the code for looping the string to capitalize every first letter.......please i would appreciate very much
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
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
Hi Josh,
I find this code for the same purpose:
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!
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;
}
#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!
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Letter-cases
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
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,
I'm trying to port this code and here's the results...with errors...
Please, can you help me to correct!
Thanks in advance,
G.VOLNY, a CSProuser from Haiti, since 2004
-
- Posts: 1807
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Letter-cases
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;
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
Thank you Greg. Since Cspro have powerful functions, i had to think in Cspro, not trying to "translate".
Best Regards,
Best Regards,
G.VOLNY, a CSProuser from Haiti, since 2004
Re: Letter-cases
Does not work for me ...keep asking for ; operator
Is word "text" a syntax or used as variable??
Is word "text" a syntax or used as variable??