string - Excel VBA insert character between number and letter -


i vba code allow me detect if string contains instances of number followed letter , insert new character between them. example:

user enters following string:

4x^2+3x 

function returns:

4*x^2+3*x 

thanks in advance.

edit: advice guys, think have working i'd see if can improve i've got:

sub insertstr()     on error resume next     dim originalstring string     dim newleft string     dim newright string     originalstring = cells(1, 1).value repeat:     = 1 len(originalstring)         if isnumeric(mid(originalstring, i, 1)) = true             select case asc(mid(originalstring, + 1, 1))                 case 65 90, 97 122                     newleft = left(originalstring, i)                     newright = right(originalstring, len(originalstring) - i)                     originalstring = newleft & "*" & newright                     goto repeat                 case else                     goto nexti             end select         end if nexti:     next end sub 

following ron's suggestion:

public function insertstar(sin string) string     dim l long, temp string, ch string     l = len(sin)     temp = left(sin, 1)     = 2 l         ch = mid(sin, i, 1)         if isletter(ch) , isnumeric(right(temp, 1))            temp = temp & "*"         end if         temp = temp & ch     next     insertstar = temp end function  public function isletter(sin string) boolean     if sin "[a-za-z]"         isletter = true     else         isletter = false     end if end function 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -