trim

jQuery text truncation (read more style)

心已入冬 提交于 2019-11-28 17:34:05
My question is very similar to " Trim text to 340 chars " but in jQuery . It sounded very straight forward but when I searched around I couldn't find any reference for it. Ok, I have a div $('#content') I want to trim the text to 'x' amount of characters lets say '600' BUT I don't want it to break the word it self! Like NOT ' The Ques... ' BUT ' The Questions... '. What happens to the rest of the text? Well, I hide it and will show it on request! But wait, it should first remove the ' ... ' and show the text right after where it hid. Here is the sample structure for $('#content'): <div id=

Removing spaces from string

大憨熊 提交于 2019-11-28 16:28:06
I'm trying to remove all the spaces from a string derived from user input, but for some reason it isn't working for me. Here is my code. public void onClick(View src) { switch (src.getId()) { case R.id.buttonGo: String input = EditTextinput.getText().toString(); input = String.replace(" ", ""); url = ur + input + l; Intent myIntent = new Intent(start.this, Main.class); myIntent.putExtra("URL", url); start.this.startActivity(myIntent); break; } } String input = EditTextinput.getText().toString(); input = input.replace(" ", ""); Sometimes you would want to remove only the spaces at the beginning

string trim function is not working [closed]

≯℡__Kan透↙ 提交于 2019-11-28 14:08:06
I learned string.trim() removes leading and trailing spaces. But in my case its not working i am trying below code but output is with leading and trailing space. But my expectation is text without leading and trailing space. Here is my code. String s = " Hello Rais "; s += " Welcome to my World "; s.trim( ); System.out.println(s); Please help me You need to re-assign the result of trim back to s : s = s.trim(); Remember, Strings in Java are immutable , so almost all the String class methods will create and return a new string, rather than modifying the string in place. Although this is off

Trim end off of string in swift, getting error at runtime

隐身守侯 提交于 2019-11-28 13:08:19
I'm making a calculator app in Swift, once my answer is obtained I want to display it in a UILabel. Only problem is I want to limit said answer to 8 characters. Here is my code: let answerString = "\(answer)" println(answer) calculatorDisplay.text = answerString.substringToIndex(advance(answerString.startIndex, 8)) This does not return any compiler errors but at runtime I get: fatal error: can not increment endIndex Any and all help would be greatly appreciated. There are two different advance() functions: /// Return the result of advancing `start` by `n` positions. ... func advance<T :

Removing blank lines from a textarea's output

♀尐吖头ヾ 提交于 2019-11-28 11:49:53
I get data from a textarea where a user has to enter a name one on each line. That data later gets split at the carriage return. Sometimes a user may add blank lines intentionally. How can I detect these lines and delete them? I'm using PHP. I dont mind using a regexp or anything else. Incorrect Data Matthew Mark Luke John James Correct Data (Note blank lines removed) Matthew Mark Luke John James Using regex to eliminate blank lines before exploding (works well for any number of consecutive blank lines, also see next snippet): $text = preg_replace('/\n+/', "\n", trim($_POST['textarea']));

Strange TrimEnd behaviour with \ char

守給你的承諾、 提交于 2019-11-28 11:07:36
问题 I am using TrimEnd to remove certain characters from the end of a string. Initially I thought this would work: Dim strNew As String = "Employees\Sickness Entitlement.rpt" Dim strTrim As String = "Sickness Entitlement.rpt" Console.WriteLine(strNew.TrimEnd(strTrim)) '<- Doesn't work But TrimEnd only works for an array of chars or a single char string, so I tried this: Dim strNew As String = "Employees\Sickness Entitlement.rpt" Dim strTrim As String = "Sickness Entitlement.rpt" Dim arrChars As

Trim part of a string in dataframe

本小妞迷上赌 提交于 2019-11-28 10:02:39
问题 If I have a dataframe structure like that: AA1_123.zip BB2_456.txt CCC_789.doc How can I change it to this: AA1 BB2 CCC 回答1: If the strings are all the same style at the start, three characters before the underline, this will work: df1 <- structure(list(Col = c("AA1_123.zip", "BB2_456.txt", "CCC_789.doc" )), .Names = "Col", class = "data.frame", row.names = c(NA, -3L)) > substr(df1$Col, 1, 3) [1] "AA1" "BB2" "CCC" 回答2: You could try sub sub('_.*', '', df1$Col) #[1] "AA1" "BB2" "CCC" data df1

Trim whitespace from parent element only

余生长醉 提交于 2019-11-28 09:39:26
问题 I'd like to trim the leading whitespace inside p tags in XML, so this: <p> Hey, <em>italics</em> and <em>italics</em>!</p> Becomes this: <p>Hey, <em>italics</em> and <em>italics</em>!</p> (Trimming trailing whitespace won't hurt, but it's not mandatory.) Now, I know normalize-whitespace() is supposed to do this, but if I try to apply it to the text nodes.. <xsl:template match="text()"> <xsl:text>[</xsl:text> <xsl:value-of select="normalize-space(.)"/> <xsl:text>]</xsl:text> </xsl:template> ..

SQL Server TRIM character

早过忘川 提交于 2019-11-28 09:09:41
I have the following string: 'BOB*', how do I trim the * so it shows up as 'BOB' I tried the RTRIM('BOB*','*') but does not work as says needs only 1 parameter. LEFT('BOB*', LEN('BOB*')-1) should do it. Another pretty good way to implement Oracle's TRIM char FROM string in MS SQL Server is the following: First, you need to identify a char that will never be used in your string, for example ~ You replace all spaces with that character You replace the character * you want to trim with a space You LTrim + RTrim the obtained string You replace back all spaces with the trimmed character * You

Remove trailing empty space in a field content

心不动则不痛 提交于 2019-11-28 08:39:15
I am using SQL server MSDE 2000. I have a field called notes of type nvarchar(65). The content is 'Something ' with an extra space after the content (quotes for clarity) in all the records. I used the following command. UPDATE TABLE1 SET notes = RTRIM(LTRIM(notes)) But it does not work. Is there any alternate way to do it? Are you sure the query isn't working? Try: SELECT TOP 100 '~'+ t.notes +'~' FROM TABLE1 t TOP 100 will limit the results to the first 100 rows, enough to get an idea if there's really a space in the output. If there is, and RTRIM/LTRIM is not removing it - then you aren't