简体   繁体   English

如果输入是 Ramesh-123-india,我如何修剪字符串...我的愿望 output 应该只是“印度”

[英]How can I trim a string if input is Ramesh-123-india ...my desire output should be only "india""

In material table one of the column has to be trim..for example input is ramesh-123-india,the output should be come as only "india"....how to do this在材料表中,其中一列必须修剪..例如输入是 ramesh-123-india,output 应该只作为“印度”来......如何做到这一点

Consider looking into the split() .考虑查看split() JavaScript docs JavaScript 文档

You can pass in a string pattern that it searches for to split it up.您可以传入它搜索的字符串模式以将其拆分。

1) You can make use of split here 1)您可以在此处使用split

 const str = "ramesh-123-india"; const result = str.split("-")[2]; console.log(result);

2) You can also use regex /\w+$/ here as: 2)您也可以在此处使用正则表达式/\w+$/作为:

在此处输入图像描述

 const str = "ramesh-123-india"; const result = str.match(/\w+$/)[0]; console.log(result);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在 Google Api javascript 中进行哪些更改,以便它只能显示印度城市而不显示州和印度? - What change should i make in Google Api javascript so it can only show the indian cities without trailing state and india? 如何事件监听并以编程方式突出显示我的印度地图的特定区域? - How to event listen and programatically highlight specific regions of my India map? 如何在Android的React Native中以编程方式打开Tez应用(印度的Google Pay应用)? - How can I open Tez app (Google Pay app in India) programmatically in React Native in Android? 如何使用 JavaScript 将我的日期“2020 年 1 月 1 日星期三 00:00:00 GMT+0530(印度标准时间)”转换为 2020 年 1 月 1 日? - How can I convert my date “Wed Jan 01 2020 00:00:00 GMT+0530 (India Standard Time) ” to JAN 01,2020 using JavaScript? 我怎样才能从我的字符串中删除特定字符? - How can i trim just specific characters from my string? 我在哪里可以获得印度的.geojson文件,而不是为每个州/地区或任何其他区别分开文件? - Where can I get the .geojson file for India and not separate files for each state/territory or any other distinction? 如何在Google Geomap中获取“班加罗尔,印度卡纳塔克邦”的区域代码? - How do i get the region code for “Bangalore,Karnataka,India” in google Geomap? 印度的IP地址范围 - Ip address range for India 如何在jsf xhtml中修剪字符串? - How can i trim string in jsf xhtml? 我需要使用javascript将用户从印度重定向到另一个页面 - I need to redirect user from India to another page using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM