string-length

Measure string size in Bytes in php

有些话、适合烂在心里 提交于 2019-11-26 15:44:35
问题 I am doing a real estate feed for a portal and it is telling me the max length of a string should be 20,000 bytes (20kb), but I have never run across this before. How can I measure byte size of a varchar string . So I can then do a while loop to trim it down. 回答1: You have to figure out if the string is ascii encoded or encoded with a multi-byte format. In the former case, you can just use strlen . In the latter case you need to find the number of bytes per character. the strlen documentation

What is the string length of a GUID?

时间秒杀一切 提交于 2019-11-26 12:49:44
问题 I want to create a varchar column in SQL that should contain N\'guid\' while guid is a generated GUID by .NET (Guid.NewGuid) - class System.Guid. What is the length of the varchar I should expect from a GUID? Is it a static length? Should I use nvarchar (will GUID ever use Unicode characters)? varchar(Guid.Length) PS. I don\'t want to use a SQL row guid data-type. I am just asking what is Guid.MaxLength . 回答1: It depends on how you format the Guid: Guid.NewGuid().ToString() => 36 characters

MySQL - How to select data by string length

你说的曾经没有我的故事 提交于 2019-11-26 08:47:14
问题 SELECT * FROM table ORDER BY string_length(column); Is there a MySQL function to do this (of course instead of string_length )? 回答1: You are looking for CHAR_LENGTH() to get the number of characters in a string. For multi-byte charsets LENGTH() will give you the number of bytes the string occupies, while CHAR_LENGTH() will return the number of characters. 回答2: select * from table order by length(column); Documentation on the length() function, as well as all the other string functions, is

Why does Python code use len() function instead of a length method?

落花浮王杯 提交于 2019-11-26 07:30:19
I know that python has a len() function that is used to determine the size of a string, but I was wondering why it's not a method of the string object. Update Ok, I realized I was embarrassingly mistaken. __len__() is actually a method of a string object. It just seems weird to see object oriented code in Python using the len function on string objects. Furthermore, it's also weird to see __len__ as the name instead of just len. Strings do have a length method: __len__() The protocol in Python is to implement this method on objects which have a length and use the built-in len() function, which

SQL Server 2008 Empty String vs. Space

主宰稳场 提交于 2019-11-26 05:23:53
问题 I ran into something a little odd this morning and thought I\'d submit it for commentary. Can someone explain why the following SQL query prints \'equal\' when run against SQL 2008. The db compatibility level is set to 100. if \'\' = \' \' print \'equal\' else print \'not equal\' And this returns 0: select (LEN(\' \')) It appears to be auto trimming the space. I have no idea if this was the case in previous versions of SQL Server, and I no longer have any around to even test it. I ran into

String field value length in mongoDB

梦想与她 提交于 2019-11-26 04:41:47
问题 The data type of the field is String. I would like to fetch the data where character length of field name is greater than 40. I tried these queries but returning error. 1. db.usercollection.find( {$where: \"(this.name.length > 40)\"} ).limit(2); output :error: { \"$err\" : \"TypeError: Cannot read property \'length\' of undefined near \'40)\' \", \"code\" : 16722 } this is working in 2.4.9 But my version is 2.6.5 回答1: For MongoDB 3.6 and newer: The $expr operator allows the use of aggregation

Length of string in bash

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 04:30:04
问题 How do you get the length of a string stored in a variable and assign that to another variable? myvar=\"some string\" echo ${#myvar} # 11 How do you set another variable to the output 11 ? 回答1: UTF-8 string length In addition to fedorqui's correct answer, I would like to show the difference between string length and byte length: myvar='Généralités' chrlen=${#myvar} oLang=$LANG oLcAll=$LC_ALL LANG=C LC_ALL=C bytlen=${#myvar} LANG=$oLang LC_ALL=$oLcAll printf "%s is %d char len, but %d bytes

Why does Python code use len() function instead of a length method?

最后都变了- 提交于 2019-11-26 01:58:31
问题 I know that python has a len() function that is used to determine the size of a string, but I was wondering why it\'s not a method of the string object. Update Ok, I realized I was embarrassingly mistaken. __len__() is actually a method of a string object. It just seems weird to see object oriented code in Python using the len function on string objects. Furthermore, it\'s also weird to see __len__ as the name instead of just len. 回答1: Strings do have a length method: __len__() The protocol