Solved

Count length of string before unique character appears

Posted on 2011-02-11
3
216 Views
Last Modified: 2012-05-11
I'm looking for some simple vb code that will count the length of text in a string before the ":" symbol appears.

Regards
Antonio
0
Comment
Question by:cbsbutler
3 Comments
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
You can use the instr-function

position = InStr("abc:def", ":") - 1

http://www.aivosto.com/vbtips/instr.html
0
 
LVL 5

Accepted Solution

by:
skrga earned 500 total points
Comment Utility
Dim strText As String
strText = "test:123"

Debug.Print Int(InStr(1, strText, ":", vbTextCompare)) - 1
0
 
LVL 8

Expert Comment

by:Den_HBR
Comment Utility
VB6:
MsgBox (InStr("ThisTextIs16Long:AndHereSomeMoreText", ":")) - 1

VB.NET:
MsgBox("ThisTextIs16Long:AndHereSomeMoreText".IndexOf(":"))
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now