string-length

compute string length in Spark SQL DSL

徘徊边缘 提交于 2019-12-10 14:21:30
问题 Edit: this is an old question concerning Spark 1.2 I've been trying to compute on the fly the length of a string column in a SchemaRDD for orderBy purposes. I am learning Spark SQL so my question is strictly about using the DSL or the SQL interface that Spark SQL exposes, or to know their limitations. My first attempt has been to use the integrated relational queries, for instance notes.select('note).orderBy(length('note)) with no luck at the compilation: error: not found: value length (Which

How to find the “real” number of characters in a Unicode string in R

假装没事ソ 提交于 2019-12-09 19:12:11
问题 I know how to find the length of a not Unicode string in R. nchar("ABC") (thanks everyone who answered the question here: How to find the length of a string in R? ). But what about Unicode strings? How to find the length of a string (number of characters in a string) in a Unicode strings? How do I find the length (in bytes) and the number of characters (runes, symbols) in a Unicode string in R? 回答1: You can use nchar for the number of characters and for the number of bytes : nchar("bi

Why does std::string(“\x00”) report length of 0?

五迷三道 提交于 2019-12-09 05:02:27
问题 I have a function which needs to encode strings, which needs to be able to accept 0x00 as a valid 'byte'. My program needs to check the length of the string, however if I pass in "\x00" to std::string the length() method returns 0. How can I get the actual length even if the string is a single null character? 回答1: You're passing in an empty string. Use std::string(1, '\0') instead. Or std::string{ '\0' } (thanks, @zett42) 回答2: std::string is perfectly capable of storing nulls. However, you

Internet Explorer Returning Wrong Length of String [duplicate]

非 Y 不嫁゛ 提交于 2019-12-09 02:55:05
问题 This question already has answers here : ToLocaleDateString() changes in IE11 (5 answers) Closed 3 years ago . 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

constexpr length of a string from template parameter

天涯浪子 提交于 2019-12-08 03:27:58
问题 I am trying to obtain the length of a string passed as a template argument using C++11. Here is what I have found so far: #include <iostream> #include <cstring> extern const char HELLO[] = "Hello World!!!"; template<const char _S[]> constexpr size_t len1() { return sizeof(_S); } template<const char _S[]> constexpr size_t len2() { return std::strlen(_S); } template<const char _S[], std::size_t _Sz=sizeof(_S)> constexpr size_t len3() { return _Sz-1; } template<unsigned int _N> constexpr size_t

string.length not working properly in java

∥☆過路亽.° 提交于 2019-12-07 07:36:05
问题 Hi I have a code that checks if a string is palindrome or not.the code is like this: package ProjeTarahi; import java.util.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; import java.lang.String; public class Main { public boolean CheckIsSymmetric(String s) { if (s.length()<=1) { return true; } if (s.charAt(0)==s.charAt(s.length()-1)) { String sub = s

How can I estimate the disk size of a string with JavaScript?

我是研究僧i 提交于 2019-12-06 23:45:18
问题 I need to try to estimate the DISK size of a text string (which could be raw text or a Base64 encoded string for an image/audio/etc) in JavaScript. I'm not sure how to estimate this. The only thing when Googling i can find is .length so i thought maybe someone on StackOverflow might know... The reason i need to know is i have a localStorage script that needs (or would love to have) the ability to check when a user is nearing his 5MB (or 10MB in IE) quota and prompt them to increase the max

Get column value length, not column max length of value

旧巷老猫 提交于 2019-12-06 18:26:23
问题 How do I get actual length of value in column? My (oracle) sql command returns maximum length of value that can be inserted in the column instead of real length of value. How to fix this? SQL> SELECT typ, length(t1.typ) FROM AUTA_VIEW t1; TYP LENGTH(T1.TYP) ---------- -------------- BMW 10 BMW 10 BMW 10 Ferrari 10 BMW 10 Audi 10 Audi 10 Audi 10 Ferrari 10 Ferrari 10 Mercedes 10 回答1: LENGTH() does return the string length (just verified). I suppose that your data is padded with blanks - try

constexpr length of a string from template parameter

孤者浪人 提交于 2019-12-06 16:48:53
I am trying to obtain the length of a string passed as a template argument using C++11. Here is what I have found so far: #include <iostream> #include <cstring> extern const char HELLO[] = "Hello World!!!"; template<const char _S[]> constexpr size_t len1() { return sizeof(_S); } template<const char _S[]> constexpr size_t len2() { return std::strlen(_S); } template<const char _S[], std::size_t _Sz=sizeof(_S)> constexpr size_t len3() { return _Sz-1; } template<unsigned int _N> constexpr size_t len5(const char(&str)[_N]) { return _N-1; } int main() { enum { l1 = len1<HELLO>(), // l2 = len2<HELLO>

C++ find size of ofstream

浪子不回头ぞ 提交于 2019-12-05 20:02:29
I have code that currently does something like the following: ofstream fout; fout.open("file.txt"); fout<<"blah blah "<<100<<","<<3.14; //get ofstream length here fout<<"write more stuff"<<endl; Is there a convenient way to find out the length of that line that is written at the stage I specified above? (in real life, the int 100 and float 3.14 are not constant and can change). Is there a good way to do what I want? EDIT: by length, I mean something that can be used using fseek, e.g. fseek(pFile, -linelength, SEEK_END); You want tellp . This is available for output streams (e.g., ostream,