Replacing variable length string with some word

前端 未结 2 2040
故里飘歌
故里飘歌 2021-01-03 17:03

Given the below string

Declare @string varchar(max)=\'abc ___________ deffns ___ cg _ hif _______hh ihs\';

this is the Output requi

相关标签:
2条回答
  • 2021-01-03 17:28

    First get rid of the multiple underscores, then do the replace.

    Here is one method:

    select replace(replace(replace(@string, '_', '><'
                                  ), '<>', ''
                          ), '><', 'LASTNAME'
                  )
    
    0 讨论(0)
  • 2021-01-03 17:36

    In C# you can use:

    string str = Regex.Replace(s, @"(_)\1{5,}", Lastname);
    

    It will match character _ if more than 5 _ occurs.

    0 讨论(0)
提交回复
热议问题