string-length

predict len of an sprintf( )'ed line?

元气小坏坏 提交于 2019-12-01 11:14:52
Is there a function around somewhere that I can use to predict the space that sprintf( ) will need? IOW, can I call a function size_t predict_space( "%s\n", some_string ) that will return the length of the C-string that will result from sprintf( "%s\n", some_string )? In C99 snprintf (note: Windows and SUSv2, do not provide an implementation of snprintf (or _snprintf) conforming to the Standard) : 7.19.6.5 The snprintf function Synopsis [#1] #include <stdio.h> int snprintf(char * restrict s, size_t n, const char * restrict format, ...); Description [#2] The snprintf function is equivalent to

concatenation and max length of string in VBA, access

耗尽温柔 提交于 2019-12-01 09:57:30
问题 I've had severas problems with strings in access-vba. The thing is, access (sometimes) limit the string's length to about 255 characters. However, depending on HOW the string was built, it may be able to grow bigger then 255 chars. There's an example of WORKING code : Dim strReq as String strReq = "SELECT exampleField1, exampleField2, exampleField3, exampleField4, exampleField5 " strReq = strRec & ", exampleField6, exampleField7, exampleField8, .... [etc. insert many fields, you get it]"

Internet Explorer Returning Wrong Length of String [duplicate]

与世无争的帅哥 提交于 2019-12-01 03:25:35
This question already has an answer here: ToLocaleDateString() changes in IE11 5 answers I've ran into a possible bug with IE where calling the JavaScript . length function returns a value that is off by 1 if/when the string was derived from .toLocaleString() . var d = new Date(); var locale = navigator.language; var month = d.toLocaleString(locale, { month: "long"}); // month.length will return the length of the month string +1 //(eg: if month = "March", month.length will return 6.) Interestingly, the code example of above will return true (in IE) for the following: (month[0] should be "M")

Number of characters in a string (not number of bytes)

丶灬走出姿态 提交于 2019-11-30 21:35:36
In a string in objective-c if I say something like [myStr length]; it returns a number which is the number of bytes but what can I use to return the number of characters in a string. For example: a string with the letter "a" in it returns a length of 1 a string with a single emoji in it returns a length of 2 (or even a length of 4 sometimes) this is because that is the number of bytes in the string... I just need the number of characters. I just whipped up this method. Add it to an NSString category. - (NSUInteger)characterCount { NSUInteger cnt = 0; NSUInteger index = 0; while (index < self

python overloading operators

寵の児 提交于 2019-11-30 21:33:19
I need to implement a DNA class which has attribute a sequence which consists of a string of characters from the alphabet ('A,C,G,T') and I need to overload some operators like less than,greater than,etc.. here is my code: class DNA: def __init__(self,sequence): self.seq=sequence def __lt__(self,other): return (self.seq<other) def __le__(self,other): return(self.seq<=other) def __gt__(self,other): return(self.seq>other) def __ge__(self,other): return(len(self.seq)>=len(other)) def __eq__(self,other): return (len(self.seq)==len(other)) def __ne__(self,other): return not(self.__eq__(self,other))

Number of characters in a string (not number of bytes)

折月煮酒 提交于 2019-11-30 17:43:37
问题 In a string in objective-c if I say something like [myStr length]; it returns a number which is the number of bytes but what can I use to return the number of characters in a string. For example: a string with the letter "a" in it returns a length of 1 a string with a single emoji in it returns a length of 2 (or even a length of 4 sometimes) this is because that is the number of bytes in the string... I just need the number of characters. 回答1: I just whipped up this method. Add it to an

python overloading operators

橙三吉。 提交于 2019-11-30 17:13:16
问题 I need to implement a DNA class which has attribute a sequence which consists of a string of characters from the alphabet ('A,C,G,T') and I need to overload some operators like less than,greater than,etc.. here is my code: class DNA: def __init__(self,sequence): self.seq=sequence def __lt__(self,other): return (self.seq<other) def __le__(self,other): return(self.seq<=other) def __gt__(self,other): return(self.seq>other) def __ge__(self,other): return(len(self.seq)>=len(other)) def __eq__(self

PHP - Get length of digits in a number

有些话、适合烂在心里 提交于 2019-11-30 11:08:12
I would like to ask how I can get the length of digits in an Integer. For example: $num = 245354; $numlength = mb_strlen($num); $numlength should be 6 in this example. Somehow I can't manage it to work? Thanks EDIT: The example code above --^ and its respective method mb_strlen(); works just fine. Maybe: $num = 245354; $numlength = strlen((string)$num); Some math sometime helps. Everything you need is to invoke floor(log10($num) + 1) with check for 0. $num = 12357; echo $num !== 0 ? floor(log10($num) + 1) : 1; Basically it does the logarithm with base 10 then makes floor of it and adds 1. More

PHP shortest/longest string in array

痴心易碎 提交于 2019-11-30 07:53:43
I have an array like this $data = array( "163", "630", "43", "924", "4", "54" ); How can I select the smallest and largest values from it according to string length NOT number value. (for this example it is 1 (smallest) and 3 (largest) . Peter Ajtai Seems like you should use an array_map() // Convert array to an array of string lengths $lengths = array_map('strlen', $data); // Show min and max string length echo "The shortest is " . min($lengths) . ". The longest is " . max($lengths); Note that the $lengths array is unsorted, so you can easily retrieve the corresponding number for each string

How do you get the length of a string?

时间秒杀一切 提交于 2019-11-29 19:38:05
How do you get the length of a string in jQuery? You don't need jquery, just use yourstring.length . See reference here and also here . Update : To support unicode strings, length need to be computed as following: [..."𠮷"].length or create an auxiliary function function uniLen(s) { return [...s].length } Andrei Iarus The easiest way: $('#selector').val().length jQuery is a JavaScript library. You don't need to use jQuery to get the length of a string because it is a basic JavaScript string object property. somestring.length; Joedel HTML <div class="selector">Text mates</div> SCRIPT alert