Sinky Posted July 26, 2021 Posted July 26, 2021 Hi! I have a question about the capitalization of sentences via calculation. I have a text field to which I usually import certain amount of text (cca. 10 sentences) in the form of sentences but without the capitalization of the first letter in a sentence. Is there a way to capitalize the fist letter of each sentence via calculation? Any help is appreciated!
comment Posted July 26, 2021 Posted July 26, 2021 9 minutes ago, Sinky said: Is there a way to capitalize the fist letter of each sentence via calculation? Maybe. It depends on whether there is a way to recognize where a sentence begins and/or ends - IOW, on your definition of what exactly is a "sentence". Can you provide a few examples of what this text field can contain?
Sinky Posted July 26, 2021 Author Posted July 26, 2021 Thank you for quick reply. I would make it simple. The first letter after the full stop should be capitalized. There is space between the full stop and first letter. I hope this helps.
comment Posted July 26, 2021 Posted July 26, 2021 (edited) 42 minutes ago, Sinky said: The first letter after the full stop should be capitalized. That is indeed simple. Perhaps even too simple - because that would exclude the very first letter in the field. Assuming that's not what you meant, and assuming a bunch of other stuff - such as that the first character after a full stop and a space is not a punctuation character, and that the field does not contain any carriage returns - you could try something like = While ( [ listOfValues = Substitute ( YourTable::Textfield ; ". " ; "¶" ) ; i = 1 ; n = ValueCount ( listOfValues ) ; result = "" ] ; i ≤ n ; [ value = GetValue ( listOfValues ; i ) ; result = List ( result ; Upper ( Left ( value ; 1 ) ) & Right ( value ; Length ( value ) - 1 ) ) ; i = i + 1 ] ; Substitute ( result ; ¶ ; ". " ) ) Edited July 26, 2021 by comment 1
Sinky Posted July 26, 2021 Author Posted July 26, 2021 Sorry I should have been more specific. The imported text is a transcription of speech via speech-to-text app. Because of this, the very first letter is always capitalized but other first letters of sentences are not. The first character after a full stop is never a punctuation character. However, there are carriage returns. Here is an example of text: Woke up early. did twenty push-ups plus 3 minute plank. skipped lunch. gym after work.
comment Posted July 26, 2021 Posted July 26, 2021 55 minutes ago, Sinky said: However, there are carriage returns. That could be handled. However, in your example, there is no space after the 2nd full stop (the one after "plank"). I am not sure if that's just an omission on your part, or is this how it is for real. Because then it starts to move away from "simple".
Sinky Posted July 26, 2021 Author Posted July 26, 2021 (edited) You're right, that's my mistake. There should be space after 2nd full stop. Edited July 26, 2021 by Sinky
comment Posted July 26, 2021 Posted July 26, 2021 (edited) 1 hour ago, Sinky said: There should be space after 2nd full stop. But then this contradicts your earlier statement: 3 hours ago, Sinky said: The first character after a full stop is never a punctuation character. Here, the first character after the full stop and space is a carriage return. So this is still not as "simple" as promised. So far I've come up with this = While ( [ listOfValues = Substitute ( YourTable::Textfield ; [ ". ¶" ; Char (1300031) ] ; [ ". " ; Char (1300030) ] ) ; i = 1 ; n = ValueCount ( listOfValues ) ; result = "" ] ; i ≤ n ; [ value = GetValue ( listOfValues ; i ) ; result = List ( result ; Upper ( Left ( value ; 1 ) ) & Right ( value ; Length ( value ) - 1 ) ) ; i = i + 1 ] ; Substitute ( result ; [ Char (1300030) ; ". " ] ; [ Char (1300031) ; ". ¶" ] ) ) See if it works for you as expected. I'll try to come back to this later to see if it can be streamlined a bit. Is there ever a case where a carriage return comes in the middle of a sentence? Edited July 26, 2021 by comment 1
Sinky Posted July 26, 2021 Author Posted July 26, 2021 Hey, no need to trouble yourself further with this. The solution you offered works perfect. Thank you once again!
Recommended Posts
This topic is 1481 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now