string-length

string.length not working properly in java

会有一股神秘感。 提交于 2019-12-05 13:01:55
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.substring(1,s.length()-2); return CheckIsSymmetric(sub); } else { return false; } } public static void main

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

耗尽温柔 提交于 2019-12-05 02:59:04
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 size for the domain. So, if a user hits, lets say, 4.5MBs of data it'd prompt with You're nearing your

Get column value length, not column max length of value

谁说胖子不能爱 提交于 2019-12-05 01:21:14
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 LENGTH() does return the string length (just verified). I suppose that your data is padded with blanks - try SELECT typ, LENGTH(TRIM(t1.typ)) FROM AUTA_VIEW t1; instead. As OraNob mentioned, another cause could be that

Runtime complexity of getting the length of a string in different representations

社会主义新天地 提交于 2019-12-04 16:46:28
In Swift 2, given a string s , what's the runtime complexity of these statements: s.characters.count s.endIndex s.utf8.count s.utf16.count s.unicodeScalars.count Also, if I know a string contains alphabets only, what's the most efficient way of getting the n-th character? OK, I'm trying to answer my own question. Feel free to correct me if I'm wrong. s.characters.count // O(N) s.endIndex // O(1) s.utf8.count // O(N) s.utf16.count // O(N) s.unicodeScalars.count // O(N) Apple's documentation on CollectionType.count says "Complexity: O(1) if Index conforms to RandomAccessIndexType ; O(N)

Index and length must refer to a location within the string error in substring

橙三吉。 提交于 2019-12-04 12:31:27
问题 I have a string like this: 2899 8761 014 00:00:00 06/03/13 09:35 G918884770707 . I have to take the substring G918884770707 from this given string. I know the start of the substring so I'm taking the end of the substring as the length of the whole string like this: No = line.Substring(Start,End); Here the value of Start is 39 and the length of the main string is 52 so this is the value for End. This causes the error: Index and length must refer to a location within the string error in

Get “actual” length of string in Unicode characters

我是研究僧i 提交于 2019-12-04 10:30:06
问题 given a character like " ✮ " ( \xe2\x9c\xae ), for example, can be others like " Σ ", " д " or " Λ ") I want to find the "actual" length that character takes when printed onscreen for example len("✮") len("\xe2\x9c\xae") both return 3, but it should be 1 回答1: You may try like this: unicodedata.normalize('NFC', u'✮') len(u"✮") UTF-8 is an unicode encoding which uses more than one byte for special characters. Check unicodedata.normalize() 回答2: My answer to a similar question: You are looking

Split string by length in Golang

两盒软妹~` 提交于 2019-12-04 01:29:30
Does anyone know how to split a string in Golang by length? For example to split "helloworld" after every 3 characters, so it should ideally return an array of "hel" "low" "orl" "d"? Alternatively a possible solution would be to also append a newline after every 3 characters.. All ideas are greatly appreciated! VonC Make sure to convert your string into a slice of rune: see " Slice string into letters ". for automatically converts string to rune so there is no additional code needed in this case to convert the string to rune first. for i, r := range s { fmt.Printf("i%d r %c\n", i, r) // every

PHP shortest/longest string in array

做~自己de王妃 提交于 2019-12-03 19:17:03
问题 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) . 回答1: 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

R base function to sort vector of strings based on length

走远了吗. 提交于 2019-12-03 14:11:31
I was wondering if there is an already made function in R base package that can sort a vector of strings taking into consideration the length of each element and then of course the lexicographical order. For instance after a sort call on some vector holding age groups you would have: v <- c("00-04", "05-09", "10-14", "100-104", "105-109", "110-114", "15-19", "20-24"..etc) whereas I would like to have: v <- c("00-04", "05-09", "10-14", "15-19", "20-24"..etc.. "100-104", "105-109", "110-114") Simply with order : v[order(nchar(v), v)] ## [1] "00-04" "05-09" "10-14" "15-19" "20-24" "100-104" "105

Get “actual” length of string in Unicode characters

拜拜、爱过 提交于 2019-12-03 06:54:08
given a character like " ✮ " ( \xe2\x9c\xae ), for example, can be others like " Σ ", " д " or " Λ ") I want to find the "actual" length that character takes when printed onscreen for example len("✮") len("\xe2\x9c\xae") both return 3, but it should be 1 You may try like this: unicodedata.normalize('NFC', u'✮') len(u"✮") UTF-8 is an unicode encoding which uses more than one byte for special characters. Check unicodedata.normalize() Simon Richter My answer to a similar question : You are looking for the rendering width from the current output context. For graphical UIs, there is usually a