Questions tagged [string-operations]

Strings or succession of characters can have various representation, either in RAM, files, databases, etc.

Their modification can programmatically be handled by various kind of function, from low level to high level.

Common operations on string can be for example:

55 questions
76
votes
7 answers

Perform a string operation for every element in a Python list

I have a list of strings in Python - elements. I would like to edit each element in elements. See the code below (it doesn't work, but you'll get the idea): for element in elements: element = "%" + element + "%" Is there a way to do this?
locoboy
  • 38,002
  • 70
  • 184
  • 260
5
votes
1 answer

Check if a string is half width or full width in C#

C# application on Japanese Windows OS - Present Latin as Full-Width characters I referred the accepted answer in the above link and is using the code below to convert Japanese string from full width to half width but it is returning the same full…
RP1
  • 275
  • 1
  • 3
  • 14
4
votes
2 answers

How to find indexes of all non-matching characters with a JS regex?

I've got a string and I want to get an array with the indexes (positions) of the characters in this string that do not match a certain regex criteria. The issue here is that if I write it like this: let match; let reg = /[A-Za-z]|[0-9]/g; let str =…
Unapedra
  • 2,043
  • 4
  • 25
  • 42
4
votes
4 answers

remove query parameter with java string operations

I have a simple problem and yet to find the optimal solution. Imagine I have a url with a query param named 'id' like any of the following…
Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
3
votes
2 answers

Get multiple characters of a string by index

I need to punch() out specific characters out of a string based on an index template (mask?). For example, I need to punch out all the characters where there is a 1 str = abcdefg mask = 0011001 // len(str) = len(mask) always print(punch(str,…
enemetch
  • 492
  • 2
  • 8
  • 21
2
votes
5 answers

How to convert string "yyyy mmm ABC" to "yyyymm" date format using Excel formula?

Suppose, in Excel, I have cell value equal to "2020 Aug ABC" I want to convert this to 202008 date format using an excel formula because I would want to use the output value, that is, 202008 to perform some operation.
2
votes
1 answer

powershell import data from text file after string

There seems to be questions that are similar floating around on the web although the answers vary and i just cannot get the outcome i am looking for. Below simply appends the content within the txt file at the end of the file Add-Content -Path…
2
votes
1 answer

BASH string operator syntax for retrieving filename

I'm trying to write a program that takes a file's name, and puts the date on it. So I'm trying to get substrings for the filename itself, and the extension. I'm new to BASH so maybe I'm missing something here, but following online guides, it seems…
2
votes
1 answer

Find occurences of strings in string and replace - php

I'm currently working on my selfmade headline-system. Therefore I'm trying to use #_1# - #_4# for numbering in the text, which should be converted in headlines then. Therefore, you write the text of the headline between the number and the second #.…
nameless
  • 1,483
  • 5
  • 32
  • 78
2
votes
1 answer

KMP Algorithm for string search?

I found this very challenging coding problem online which I though I'd give a try. The general idea is that given string of text T and pattern P, find the occurrences of this pattern, sum up it's corresponding value and return max and min. If you…
user7947407
2
votes
2 answers

How do I check if a line is a valid function call in python?

Background: I'm currently creating a line-magic for ipython. This magic shall only work for lines, where the return value of a function is assigned to a variable. I'm looking for a way to make sure, that a line is a valid function-call + assignment…
wotanii
  • 2,470
  • 20
  • 38
2
votes
0 answers

How to replace a character in string

I'm writing a function to replace all underscores in a string with dashes. For example: underscores_to_dashes("erlang_is_great") = "erlang-is-great" At the moment I'm using the following function: underscores_to_dashes(String) -> [case Char of…
Sergey Ovchinnik
  • 472
  • 4
  • 16
1
vote
1 answer

How to grab a substring from a given string?

Basically I have following strings and I want to grab a sub-string from them. input: RT4_MANGO_AF output: MANGO input: RT4_DF5_WE_APPLE_AF output: APPLE input: TF_WE_BANANA_AF output: BANANA input: RT4_DF5_ORANGE_AF output: ORANGE Note the…
mac
  • 863
  • 3
  • 21
  • 42
1
vote
3 answers

How to use case-agnostic-string-matching-condition in a Python list comprehension?

Is there a way to make a list comprehension to search for a string being case insensitive? What I do now, which is subpar is: original_list = ['NAME', 'NUMBER', 'name', 'number', 'Name', 'NaMe', 'place'] filtered_list = [x for x in LIST if "NAME"…
1
vote
1 answer

Manipulating directories in Java Ant

I have an Ant xml file. In this file I want to set two properties based on the current working directory. The current working directory is always of the form /some/base/dir/SRC/sub/dir. The first property must be set to the current working…
Andrew Vickers
  • 2,504
  • 2
  • 10
  • 16
1
2 3 4