lowercase

Swap case of letters in string input parameter [closed]

核能气质少年 提交于 2019-12-03 15:11:27
I would like to write a function in Python that takes a string which has lower and upper case letters as a parameter and converts upper case letters to lower case, and lower case letters to upper case. For example: >>> func('DDDddddd') 'dddDDDDD' I want to do it with strings but I couldn't figure out how. EDIT - Way simpler than my original answer, and supports both ASCII and unicode. Thanks commenters. a = 'aBcD' a.swapcase() >> AbCd Original answer - disregard a = 'aBcD' ''.join(map(str.swapcase, a)) >> AbCd This will map the str.swapcase() function to each element of the string a , swapping

Why should the first letter of a Java class be upper-cased? [closed]

不想你离开。 提交于 2019-12-03 14:40:20
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Why should the first letter of a Java class be upper-cased? Is it not possible to run a program containing lower-cased class names? If

Turn off upper-case for table and column names in HSQL?

[亡魂溺海] 提交于 2019-12-03 13:31:27
How to turn off forced upper-case mode for table and column names in HSQL? <artifactId>hsqldb</artifactId> <version>2.3.1</version> OS: Windows 7 x64 The rules around this are explained in the HSQLDB documentation : When a database object is created with one of the CREATE statements or renamed with the ALTER statement, if the name is enclosed in double quotes, the exact name is used as the case-normal form. But if it is not enclosed in double quotes, the name is converted to uppercase and this uppercase version is stored in the database as the case-normal form. Case sensitivity rules for

how to convert Lower case letters to upper case letters & and upper case letters to lower case letters

和自甴很熟 提交于 2019-12-03 12:36:06
Alternately display any text that is typed in the textbox // in either Capital or lowercase depending on the original // letter changed. For example: CoMpUtEr will convert to // cOmPuTeR and vice versa. Switch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e ) String characters = (SecondTextField.getText()); //String to read the user input int length = characters.length(); //change the string characters to length for(int i = 0; i < length; i++) //to check the characters of string.. { char character = characters.charAt(i); if(Character.isUpperCase(character)) {

Django LowerCaseCharField

六月ゝ 毕业季﹏ 提交于 2019-12-03 12:22:00
We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions. from django.db.models.fields import CharField class LowerCaseCharField(CharField): """ Defines a charfield which automatically converts all inputs to lowercase and saves. """ def pre_save(self, model_instance, add): """ Converts the string to lowercase before saving. """ current_value = getattr(model_instance, self.attname) setattr(model_instance, self.attname, current_value.lower()) return getattr(model_instance, self.attname) In fact we love to have is: > modelinstance.field_name="TEST" > print

Ruby on Rails uncapitalize first letter

不想你离开。 提交于 2019-12-03 10:32:54
问题 I'm running Rails 2.3.2. How do I convert "Cool" to "cool" ? I know "Cool".downcase works, but is there a Ruby/Rails method that does the opposite of capitalize , i.e., uncapitalize or decapitalize ? 回答1: There is no inverse of capitalize , but you can feel free to roll your own: class String def uncapitalize self[0, 1].downcase + self[1..-1] end end 回答2: There is also: "coolat_cat".camelize(:lower) # => "coolCat" 回答3: You could also do this with a simple sub : "Cool".sub(/^[A-Z]/) {|f| f

python 2.7 lowercase

旧巷老猫 提交于 2019-12-03 09:50:42
When I use .lower() in Python 2.7, string is not converted to lowercase for letters ŠČŽ . I read data from dictionary. I tried using str(tt["code"]).lower() , tt["code"].lower() . Any suggestions ? Use unicode strings: drostie@signy:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print "ŠČŽ" ŠČŽ >>> print "ŠČŽ".lower() ŠČŽ >>> print u"ŠČŽ".lower() ščž See that little u ? That means that it's created as a unicode object rather than a str object. Use unicode: >>> print u'ŠČŽ'.lower().encode(

.toLowerCase not working, replacement function?

偶尔善良 提交于 2019-12-03 08:08:06
问题 The .toLowerCase method is giving me an error when I try to use it on numbers. This is what I have: var ans = 334; var temp = ans.toLowerCase(); alert(temp); And then it gives me this error: 'undefined' is not a function (evaluating 'ans.toLowerCase()') I don't know where I got this wrong. I always thought that numbers can also be parsed, with no change in result (maybe that's where I stuffed up). But if that's not the error, can someone write a custom makeLowerCase function, to make the

Permutate a String to upper and lower case

烂漫一生 提交于 2019-12-03 07:25:25
I have a string, "abc". How would a program look like (if possible, in Java) who permute the String? For example: abc ABC Abc aBc abC ABc abC AbC Something like this should do the trick: void printPermutations(String text) { char[] chars = text.toCharArray(); for (int i = 0, n = (int) Math.pow(2, chars.length); i < n; i++) { char[] permutation = new char[chars.length]; for (int j =0; j < chars.length; j++) { permutation[j] = (isBitSet(i, j)) ? Character.toUpperCase(chars[j]) : chars[j]; } System.out.println(permutation); } } boolean isBitSet(int n, int offset) { return (n >> offset & 1) != 0;

SQL changing a value to upper or lower case

混江龙づ霸主 提交于 2019-12-03 06:28:06
问题 How do you make a field in a sql select statement all upper or lower case? Example: select firstname from Person How do I make firstname always return upper case and likewise always return lower case? 回答1: SELECT UPPER(firstname) FROM Person SELECT LOWER(firstname) FROM Person 回答2: LCASE or UCASE respectively. Example: SELECT UCASE(MyColumn) AS Upper, LCASE(MyColumn) AS Lower FROM MyTable 回答3: SQL SERVER 2005: print upper('hello'); print lower('HELLO'); 回答4: You can use LOWER function and