Forum Discussion

Romel_77740's avatar
Romel_77740
Icon for Nimbostratus rankNimbostratus
Aug 03, 2010

string manipulation

-- I have a string S. There is a character '>' in S. I want to insert a new string in between '>' and the character before '>'. What's the best way to do this? -- I have a string S. There is a character ';' and '@' in S. I want to remove all character in between ';' (including this) and '@' (not including this). What's the best way to do this?

3 Replies

  • Hi Romel,

     

     

    Does the first string S have more than one >'s in it? If so can you provide some sanitized examples of the original and updated versions?

     

     

    Likewise, are there more than one ; or @ character in the second string? Can you also provide some sanitized examples of the original and updated versions for that scenario?

     

     

    Aaron
  • Example for 1st case: 12344384616;cic=0335@@645.444.44 Example for 2nd case: <34384616@66.106ddsdsd>
  • Maybe something like these?

     

     

    set str1 "12344384616;cic=0335@@645.444.44"

     

     

    scan $str1 and save everything that isn't a ; into a.

     

    Save everything after ; up to the next @ into b

     

    Save everything after the @ into c

     

    scan $str1 {%[^;];%[^@]@%s} a b c

     

     

    Append $a and $c

     

    set str1_edited "$a$c"

     

     

    Result: 12344384616@645.444.44

     

     

    Replace all >'s with inserted_string>

     

    string map {">" "inserted_string>"} "<34384616@66.106ddsdsd>"

     

     

    Result: <34384616@66.106ddsdsdinserted_string>

     

     

    Aaron