Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Alternate ways to extract a substring?

I have the following simple code:

sTxt = Mid(sSentence, 14, 5)

This code copies 5 characters from the string contained
in the variable "sSentence", starting at position 14.

My question is, is there another way to do the same
exact thing WITHOUT using the "Mid()" function???

I'm basically trying to find other ways to extract substrings
without using the MID() function.

Thank you!

Robert Crandal


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Alternate ways to extract a substring?

On Fri, 15 Apr 2011 01:45:00 -0700, "Robert Crandal" wrote:

I have the following simple code:

sTxt = Mid(sSentence, 14, 5)

This code copies 5 characters from the string contained
in the variable "sSentence", starting at position 14.

My question is, is there another way to do the same
exact thing WITHOUT using the "Mid()" function???

I'm basically trying to find other ways to extract substrings
without using the MID() function.

Thank you!

Robert Crandal


Here are several methods

=====================
Option Explicit
Sub foo()
Const S As String = "Now is the time for all"
Debug.Print Mid(S, 14, 5)

'Use combination of Left and Right
Debug.Print Left(Right(S, Len(S) - (14 - 1)), 5)

'Using nested worksheet function REPLACE
With WorksheetFunction
Debug.Print .Replace(.Replace([A1], 1, 13, ""), 5 + 1, 99, "")
End With

'Using regular Expressions
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "^[\s\S]{13}([\s\S]{5})[\s\S]*"
Debug.Print re.Replace(S, "$1")

Debug.Print vbLf

End Sub
==========================
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Userform two ways Ray Excel Programming 3 October 2nd 09 04:28 PM
The error of my ways. Cerberus Excel Discussion (Misc queries) 5 February 19th 08 09:36 PM
different ways to copy a range? botha822[_3_] Excel Programming 4 August 8th 06 12:06 AM
Ways of Summarising data BM Excel Discussion (Misc queries) 1 February 2nd 06 09:07 AM
Ways to activate a macro eddied Excel Discussion (Misc queries) 2 February 7th 05 07:00 AM


All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"