strip

Removing leading zeros before passing a shell variable to another command

倾然丶 夕夏残阳落幕 提交于 2019-11-27 01:28:06
问题 It turns out that iptables doesn't handle leading zeros too well. As $machinenumber that is used has to have a leading zero in it for other purposes, the idea is simply to create a new variable ( $nozero ) based on $machinenumber , where leading zeros are stripped away. $machinenumber is a two-digit number between 01 and 24. Currently it's 09 $machinetype is 74 for now and hasn't caused any problems before. What I have so far is: nozero = (echo $machinenumber | sed 's/^0*//') iptables -t nat

Delete first 3 characters and last 3 characters from String PHP

限于喜欢 提交于 2019-11-27 01:24:01
I need to delete the first 3 letters of a string and the last 3 letters of a string. I know I can use substr() to start at a certain character but if I need to strip both first and last characters i'm not sure if I can actually use this. Any suggestions? Pass a negative value as the length argument (the 3rd argument) to substr() , like: $result = substr($string, 3, -3); So this: <?php $string = "Sean Bright"; $string = substr($string, 3, -3); echo $string; ?> Outputs: n Bri James Use substr($var,1,-1) this will always get first and last without having to use strlen. Example: <?php $input = ",a

String strip() for JavaScript? [duplicate]

久未见 提交于 2019-11-26 18:54:17
问题 This question already has an answer here: Trim string in JavaScript? 26 answers What's a clean and efficient JavaScript implementation to strip leading and trailing spaces from a string? For example: " dog" "dog " " dog " " dog " all get turned into "dog" 回答1: Use this: if(typeof(String.prototype.trim) === "undefined") { String.prototype.trim = function() { return String(this).replace(/^\s+|\s+$/g, ''); }; } The trim function will now be available as a first-class function on your strings.

Strip whitespace and newlines from XML in Java

孤者浪人 提交于 2019-11-26 17:51:03
问题 Using Java, I would like to take a document in the following format: <tag1> <tag2> <![CDATA[ Some data ]]> </tag2> </tag1> and convert it to: <tag1><tag2><![CDATA[ Some data ]]></tag2></tag1> I tried the following, but it isn't giving me the result I am expecting: DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); dbfac.setIgnoringElementContentWhitespace(true); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse(new FileInputStream("/tmp

002---Python基本数据类型--字符串

烈酒焚心 提交于 2019-11-26 17:28:47
  定义:字符串是一个有序的字符集合,用来存储和表示文本信息。用双引和单引表示。是一种不可变类型。      创建:      In [9]:      s = 'Hello Python'      print(s)      Hello Python      常用操作:      In [1]:      # 索引和切片      s = 'Python'      print(s[1]) # y      print(s[-1]) # n      print(s[1:4]) # yth 顾头不顾尾      y      n      yth      In [2]:      # capitalize() 首字母大写      s = 'hello python'      print(s.capitalize()) # Hello python      Hello python      In [3]:      # upper() lower() 全大写和全小写      s1 = 'hello python'      s2 = 'HELLO PYTHON'      print(s1.upper()) # Hello python      print(s2.lower()) # hello python      HELLO PYTHON     

Strip HTML tags and its contents

霸气de小男生 提交于 2019-11-26 16:45:35
问题 I'm using DOM to parse string. I need function that strips span tags and its contents. For example, if I have: This is some text that contains photo. <span class='title'> photobyile</span> I would like function to return This is some text that contains photo. This is what I tried: $dom = new domDocument; $dom->loadHTML($string); $dom->preserveWhiteSpace = false; $spans = $dom->getElementsByTagName('span'); foreach($spans as $span) { $naslov = $span->nodeValue; echo $naslov; $string = preg

How to strip type from Javascript FileReader base64 string?

人走茶凉 提交于 2019-11-26 15:57:50
问题 I've got the following code in my Javascript: var reader = new FileReader(); reader.onloadend = function () { alert(reader.result); }; This shows me the following data: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAAAAABX3VL4AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gYSDCUgSze0AAAAAA5JREFUCNdjrGJgYmAAAAJ0AH4SDHVIAAAAAElFTkSuQmCC The thing is that I only want the part after the comma. I tried getting it from reader.result.value , reader.result.valueOf() and some other combinations,

Best way to automatically remove comments from PHP code

a 夏天 提交于 2019-11-26 15:50:56
Whats the best way to remove comments from a PHP file? I want to do something similar to strip-whitespace() - but it shouldn't remove the line breaks as well. EG: I want this: <?PHP // something if ($whatsit) { do_something(); # we do something here echo '<html>Some embedded HTML</html>'; } /* another long comment */ some_more_code(); ?> to become: <?PHP if ($whatsit) { do_something(); echo '<html>Some embedded HTML</html>'; } some_more_code(); ?> (Although if the empty lines remain where comments are removed, that wouldn't be ok). It may not be possible, because of the requirement to preserve

Python strip with \n [duplicate]

孤人 提交于 2019-11-26 15:50:51
问题 This question already has an answer here: rstrip not removing newline char what am I doing wrong? [duplicate] 3 answers This is my problem. I'm trying to read a text file and then convert the lines into floats. The text file has \n and \t in it though I don't know how to get rid of it. I tried using line.strip() but it didn't take it off and I got an error when I wanted to convert the stuff to floats. I then tried line.strip("\n") but that didn't work either. My program works fine when I take

Vim run autocmd on all filetypes EXCEPT

风流意气都作罢 提交于 2019-11-26 15:23:23
问题 I have a Vim autocmd that removes trailing whitespace in files before write. I want this almost 100% of the time, but there are a few filetypes that I'd like it disabled. Conventional wisdom is to list the filetypes you want an autocmd to run against in a comma-separated list, eg: autocmd BufWritePre *.rb, *.js, *.pl But in this case that would be onerous. Is there a way to match an autocmd pattern against all files EXCEPT those matching the pattern? I cannot find the equivalent to a NOT