letter

Determine if string starts with letters A through I

﹥>﹥吖頭↗ 提交于 2019-11-30 23:40:42
问题 I've got a simple java assignment. I need to determine if a string starts with the letter A through I. I know i have to use string.startsWith(); but I don't want to write, if(string.startsWith("a")); all the way to I, it seems in efficient. Should I be using a loop of some sort? 回答1: You don't need regular expressions for this. Try this, assuming you want uppercase only: char c = string.charAt(0); if (c >= 'A' && c <= 'I') { ... } If you do want a regex solution however, you can use this

How can I check if a char is a letter or a number?

纵然是瞬间 提交于 2019-11-30 03:57:44
问题 I have a string and I want to loop it so that I can check if every char is a letter or number. $s = "rfewr545 345b"; for ($i=1; $i<=strlen($s); $i++){ if ($a[$i-1] == is a letter){ echo $a[$i-1]." is a letter"; } else { echo $a[$i-1]." is a number"; } } How can I check if a char is a letter or a number? 回答1: To test if character is_numeric , use: is_numeric($a[$i-1]) As below: $s = "rfewr545 345b"; for ($i = 0; $i < strlen($s); $i++){ $char = $s[$i]; if (is_numeric($char)) { echo $char . ' is

In VB6 what is the difference between Property Set and Property Let?

拜拜、爱过 提交于 2019-11-27 21:02:16
I have just created several Property Set methods, and they didn't compile. When I changed them to Property Let , everything was fine. I have since studied the documentation to find the difference between Property Set and Property Let , but must admit to being none the wiser. Is there any difference, and if so could someone offer a pointer to a proper explanation of it? Property Set is for objects (e.g., class instances) Property Let is for "normal" datatypes (e.g., string, boolean, long, etc.) Property Let is more versatile than Property Set . The latter is restricted to object references only

Randomly choosing from a list with weighted probabilities

旧巷老猫 提交于 2019-11-27 13:43:40
I have an array of N elements (representing the N letters of a given alphabet), and each cell of the array holds an integer value, that integer value meaning the number of occurrences in a given text of that letter. Now I want to randomly choose a letter from all of the letters in the alphabet, based on his number of appearances with the given constraints: If the letter has a positive (nonzero) value, then it can be always chosen by the algorithm (with a bigger or smaller probability, of course). If a letter A has a higher value than a letter B, then it has to be more likely to be chosen by

How to check if character is a letter in Javascript?

余生颓废 提交于 2019-11-27 07:02:40
I am extracting a character in a Javascript string with: var first = str.charAt(0); and I would like to check whether it is a letter. Strangely, it does not seem like such functionality exists in Javascript. At least I cannot find it. How can I test this? I believe this plugin has the capabilities you seek: http://xregexp.com/plugins/ (github link: https://github.com/slevithan/xregexp ) With it you can simply match all unicode letters with \p{L} . Read the header of this source file to see which categories it supports: http://xregexp.com/plugins/xregexp-unicode-categories.js I don't believe

Regex capitalize first letter every word, also after a special character like a dash

帅比萌擦擦* 提交于 2019-11-27 04:36:41
I use this #(\s|^)([a-z0-9-_]+)#i for capitalize every first letter every word, i want it also to capitalize the letter if it's after a special mark like a dash(-) Now it shows: This Is A Test For-stackoverflow And i want this: This Is A Test For-Stackoverflow Any suggestions/samples for me? I'am not a pro, so try to keep it simple for me to understand. A simple solution is to use word boundaries : #\b[a-z0-9-_]+#i Alternatively, you can match for just a few characters: #([\s\-_]|^)([a-z0-9-_]+)#i +1 for word boundaries, and here is a comparable Javascript solution. This accounts for

In VB6 what is the difference between Property Set and Property Let?

青春壹個敷衍的年華 提交于 2019-11-26 20:31:31
问题 I have just created several Property Set methods, and they didn't compile. When I changed them to Property Let , everything was fine. I have since studied the documentation to find the difference between Property Set and Property Let , but must admit to being none the wiser. Is there any difference, and if so could someone offer a pointer to a proper explanation of it? 回答1: Property Set is for objects (e.g., class instances) Property Let is for "normal" datatypes (e.g., string, boolean, long,

How to check if character is a letter in Javascript?

懵懂的女人 提交于 2019-11-26 10:38:42
问题 I am extracting a character in a Javascript string with: var first = str.charAt(0); and I would like to check whether it is a letter. Strangely, it does not seem like such functionality exists in Javascript. At least I cannot find it. How can I test this? 回答1: I believe this plugin has the capabilities you seek: http://xregexp.com/plugins/ (github link: https://github.com/slevithan/xregexp) With it you can simply match all unicode letters with \p{L} . Read the header of this source file to

python capitalize first letter only

孤街浪徒 提交于 2019-11-26 09:20:24
问题 I am aware .capitalize() capitalizes the first letter of a string but what if the first character is a integer? this 1bob 5sandy to this 1Bob 5Sandy 回答1: If the first character is an integer, it will not capitalize the first letter. >>> '2s'.capitalize() '2s' If you want the functionality, strip off the digits, you can use '2'.isdigit() to check for each character. >>> s = '123sa' >>> for i, c in enumerate(s): ... if not c.isdigit(): ... break ... >>> s[:i] + s[i:].capitalize() '123Sa' 回答2:

Regex to match only letters

雨燕双飞 提交于 2019-11-26 01:27:09
问题 How can I write a regex that matches only letters? 回答1: Use a character set: [a-zA-Z] matches one letter from A–Z in lowercase and uppercase. [a-zA-Z]+ matches one or more letters and ^[a-zA-Z]+$ matches only strings that consist of one or more letters only ( ^ and $ mark the begin and end of a string respectively). If you want to match other letters than A–Z, you can either add them to the character set: [a-zA-ZäöüßÄÖÜ] . Or you use predefined character classes like the Unicode character