String manipulation

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
newguy79
Posts: 9
Last visit: Thu Jun 14, 2007 1:38 am

String manipulation

Post by newguy79 »

I am still fairly new to the VBScript environment. Anyhow, I need some help in determining if there are any functions that can determine if a particular string has X number of characters or symbols.
For example: I have string that contains "Today is ******* good". How do I determine X number of "*" in the string. I know that I can use the "Split" method to break up the words and then use the "InStr" method to determine "*" X position of the character. It does count but it can't give me the exact number of "*".

Any help would be good.
User avatar
newguy79
Posts: 9
Last visit: Thu Jun 14, 2007 1:38 am

String manipulation

Post by newguy79 »

I am still fairly new to the VBScript environment. Anyhow, I need some help in determining if there are any functions that can determine if a particular string has X number of characters or symbols.
For example: I have string that contains "Today is ******* good". How do I determine X number of "*" in the string. I know that I can use the "Split" method to break up the words and then use the "InStr" method to determine "*" X position of the character. It does count but it can't give me the exact number of "*".

Any help would be good.
User avatar
newguy79
Posts: 9
Last visit: Thu Jun 14, 2007 1:38 am

String manipulation

Post by newguy79 »

Here is the code. This code keeps giving me back a position 3 even though I use position 3 to search for. If I was to increment the search start position, it returns nothing for me. I am a little confused.
I know it is not necessary to split up the words but to make it easier, I split the string up.

Code: Select all

	
  Dim totalNumberOfCellsOnPartitionArray(1, 7)  '2 Dimensional array - First dimension is for Cabinets and Second dimension is for Cell Slots
  
  searchTextArray = "Part  1 |..**|"
	
  For r = 0 to 1
   For c = 0 to 7
    totalNumberOfCellsOnPartitionArray(r, c) = False
   Next
  Next
  
  splitTextArray = Split(searchTextArray, "|", -1, 1)
  cellPositionFound = 0
  cellPositionFoundTemp = 0
  cabinetIndex = 0
  For splitIndex = 0 to UBound(splitTextArray)
  
   cellPositionFound = Instr(1, splitTextArray(splitIndex), "*", 1)
   
   While cellPositionFound  0 
	
    lenTest = Len(splitTextArray(splitIndex))
    
    totalNumberOfCellsOnPartitionArray(cabinetIndex, cellPositionFound - 1) = True
    cellPositionFoundTemp = Instr(cellPositionFound, splitTextArray(splitIndex), "*", 1)
    
    If cellPositionFound  cellPositionFoundTemp Then
     cellPositionFound = cellPositionFoundTemp
    Else
     cellPositionFound = 0
    End If
   Wend
  Next 
newguy792007-05-23 10:07:28
User avatar
newguy79
Posts: 9
Last visit: Thu Jun 14, 2007 1:38 am

String manipulation

Post by newguy79 »

Thanks jvierra! But i figured it out and it is using the Mid() function.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

String manipulation

Post by jvierra »

I just ran into the same need last week so it was fresh in my head.

There are many other methods but that is the esiest and probably teh most efficient.

Regular expression are actualy more powerful but need a liitle learning curve.
This topic is 16 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked