10 examples of 'python strip newline from string' in Python

Every line of 'python strip newline from string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
16def strip_after_new_lines(s):
17 """Removes leading and trailing whitespaces in all but first line.
18
19 :param s: string or BibDataStringExpression
20 """
21 if isinstance(s, BibDataStringExpression):
22 s.apply_on_strings(_strip_after_new_lines)
23 return s
24 else:
25 return _strip_after_new_lines(s)
202def remove_newlines(string):
203 string = string.replace("\n", "")
204 return string.replace("\r", "")
37def strip_eol(line):
38 while line and line[-1] in '\r\n':
39 line = line[:-1]
40 return line
25def strip_space(string):
26 """ strip space after :, remove newlines, replace
27 multiple spaces with only one space, remove comments """
28 if isinstance(string, basestring):
29 string = re_line1.sub('', re_sep.sub(':', string))
30 string = re_comments.sub('', string.strip())
31 return string
148def strip_ws(self, *strings):
149 ans = ''
150 for s in strings:
151 for c in s:
152 if not c.isspace():
153 ans += c
154 return ans
38def strip_space(string):
39 """Remove spaces from string
40
41 :argument string: target string
42 :type string: str
43
44 :returns str
45
46 """
47 return string.replace(' ', '')
169def strip_bom(string: str) -> str:
170 """
171 Remove the Unicode Byte Order Mark from a string.
172
173 INPUTS
174 string: A Unicode string
175
176 OUTPUTS
177 The input string with the Byte Order Mark removed
178 """
179
180 if string.startswith(UNICODE_BOM):
181 string = string[1:]
182
183 return string
153def _fix_newlines(s):
154 # Replace the characters "\r\n", "\r" and "\n" with \R.
155 # Does not affect the substrings '\' + 'n' or '\' + 'n'
156 s = string.replace(s, "\r\n", "\n")
157 s = string.replace(s, "\r", "\n")
158 return string.replace(s, "\n", r"\R")
162def strip_spaces(s):
163 """ Strip excess spaces from a string """
164 return u" ".join([c for c in s.split(u' ') if c])
67def clean_lines(string_list, remove_empty_lines=True):
68 """
69 Strips whitespace, \n and \r and empty lines from a list.
70
71 Args:
72 string_list:
73 List of strings
74 remove_empty_lines:
75 Set to True to skip lines which are empty after stripping.
76
77 Returns:
78 List of clean strings with no whitespaces.
79 """
80
81 for s in string_list:
82 clean_s = s
83 if '#' in s:
84 ind = s.index('#')
85 clean_s = s[:ind]
86 clean_s = clean_s.strip()
87 if (not remove_empty_lines) or clean_s != '':
88 yield clean_s

Related snippets