VBScript string replace with range instead of string?

前端 未结 2 739
无人及你
无人及你 2021-01-29 01:16

Replace() already exists, but that function takes strings as parameters. I need range.

In my string there are two \"strings\" that are 10 characters long. Greger with 6

2条回答
  •  無奈伤痛
    2021-01-29 01:52

    If they're always going to be 10 chars, just pad the names.

    strNameFind    = "Greger"
    strNameReplace = "googlioa"
    
    ' Pad the names...
    strNameFind    = Left(strNameFind    & Space(10), 10)
    strNameReplace = Left(strNameReplace & Space(10), 10)
    
    MyString = Replace(MyString, strNameFind, strNameReplace)
    

    Alternatively, if you don't want to determine the existing name, just pad your new name appropriately and add the remainder of your string:

    ' Pad the new name to fit in a 10-char column...
    strNameReplace = "googlioa"
    strNameReplace = Left(strNameReplace & Space(10), 10)
    
    ' Update the record...
    MyString = strNameReplace & Mid(MyString, 11)
    

提交回复
热议问题