How to Specify a Dynamic Position for the Start of Substring

How do I specify a dynamic position for the start of substring?

you can use sub()

video_data_2$Video_full <- sub("^.*\\.","", video_data_2$Video_full)

In a dynamic string, how to start a substring at a certain character and end it at certain character?

After edits, you can simply do this for your requirements:

var string = "BLAH BLAH BLAH width: 673px; height: 123px; BLAH BLAH BLAH width: 1009px; height: 237px; BLAH BLAH";
var regExp = /(\b\w+:[^:]*px)/g
string = string.replace(regExp,'')

With regex, you can do like this:

var string = "BLAH BLAH BLAH width: 673px; height: 123px; BLAH BLAH BLAH width: 1009px; height: 237px; BLAH BLAH";
var regExp = /(\b\w+:[^:]*px)/g
var match = regExp.exec(string);
while(match != null)
{
var width = match[1]
match = regExp.exec(string);
var height = match[1]
match = regExp.exec(string);
}

After this, In each iteration, the variable width will have the substring width: 4874px and the variable height will have the substring height: 898px

Extract substring in R from string with fixed start position and end point as a character found

You could try this:

a<-"http://www.imdb.com/title/tt2569314/companycredits"
sub("http://www.imdb.com/.+/(.+)/.+","\\1" ,a)
#[1] "tt2569314"

How to substring of a string with dynamically changing long text where indexes are unknown

You can use the indexof function to get the position of you starting subString :

text.substring(text.indexOf("As of 2016"), text.length);

Substring index with dynamic value and 1 column result

You can join the tables, group by code an use GROUP_CONCAT() to collect the tag values:

SELECT t.code,
GROUP_CONCAT(m.value ORDER BY m.id) tag_value
FROM tag t INNER JOIN master_tag m
ON FIND_IN_SET(m.id, t.tag_customer)
GROUP BY t.code;

See the demo.

Get specific part of dynamic string in TSQL

Assuming your items values can't contain ZZ and ,ZZ patterns (so they can be considered as real delimiters) you can do it using bunch of charindex and substring:

declare @src nvarchar(max), @Start_Position int, @End_Position int
select @src = 'AA=Item0,ZZ=Item1,ZZ=Item2,ZZ=Item3,ZZ=Item4,ZZ=Item5'

select @Start_Position = charindex('ZZ', @src, charindex('ZZ', @src) + 1) + 3
select @End_Position = charindex(',ZZ', @src, @Start_Position)

select substring(@src, @Start_Position, @End_Position - @Start_Position)

Explanation:

  1. Find occurence of first ZZ in the string: charindex('ZZ', @src)
  2. Find occurence of next ZZ starting from position of first ZZ and add three characters - it will be position where Item2 starts.
  3. Find occurence of ,ZZ characters starting from position determined in previous step - it will be bosition where Item2 ends.
  4. Do substring.

Insert string into string on a dynamic position





const text = "[GREEN][BLUE][RED]";
const inputNumber = 2;
const addingText = "[YELLOW]";

const index = text.split("[", inputNumber).join("[").length;
const output = [text.slice(0, index), addingText, text.slice(index)].join('');

console.log(output)

How to dynamically find the position of string in sql server?

To find a position of a substring in a string you can use CHARINDEX()

If you want to extract the number from your string you can do

SELECT SUBSTRING(s, 
CHARINDEX('<#', s) + 2,
CHARINDEX('#/>', s) - CHARINDEX('<#', s) - 2) number
FROM
(
SELECT 'What is <#1#/>' s
) q

Here is SQLFiddle demo



Related Topics



Leave a reply



Submit