1

I have string like this:

река Марица - гр. Първомай + Maritsa - 132543 - HPoint-Water level

I want to get only Maritsa - 132543 - HPoint-Water level with javascript.

For now I get the string and console log all string, but I need to cut the cyrillic string and - before Maritsa. The problem is that the loaded names are always different. Is there a way to delete everything before the + including it and show everything after the +

image

6
  • why not take directly? Commented Jan 23, 2023 at 18:46
  • Because this data is loaded in a dropdown and from the selected value I want to take only that part that I need to be submitted as a parameter in another request. Commented Jan 23, 2023 at 18:48
  • you need some definition. the length does not work, it returns 'tsa - 132543 - HPoint-Water level' Commented Jan 23, 2023 at 18:49
  • I update my question, can you check please :) Commented Jan 23, 2023 at 18:53
  • 1
    so, str.split('+')[1]? Commented Jan 23, 2023 at 18:59

2 Answers 2

1

You could replace the unwanted part.

const s = 'река Марица - гр. Първомай + Maritsa - 132543 - HPoint-Water level';

console.log(s.replace(/.*\+\s?/, ''));

Sign up to request clarification or add additional context in comments.

Comments

1

You can combine String.prototype.indexOf (which returns the first occurence of a char) and Array.prototype.slice (to return the string only after a certain index, here after the + and the space after it) :

const name = 'река Марица - гр. Първомай + Maritsa - 132543 - HPoint-Water level'

const cutString = string => string.slice(string.indexOf('+') + 2)
//           add 2 to also remove the + and the space after it ^ 

console.log(`"${ cutString(name) }"`)

Hope it helped you !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.