I got trouble to give space between words on sql, before on sql I already did on vb.net:
'============================= Create Space Between Words ========================'
'Split The Words into 3 line'
' Lang if 0 english else if 1 Indonesian'
Dim ReceiptTextWords As String() = receiptText.Split("+")
'================================== First Line ==================================='
' This is how the third line appears in the string array after the space splitting'
Dim ReceiptTextWord1 As String() = ReceiptTextWords(0).Split(" ")
' This array contains the spaces reserved for each word in the string array above'
If lang = "0" Then
' MM YY : 0610 REF. NO : 1234567890 R.WAHYUDIYONO,IR '
Dim spaces1 = New Integer() {3, 10, 2, 16, 5, 7, 2, 16, 29}
' Now loop on the strings and format them as indicated by the spaces'
' Attention, the value for space include the string itself'
Dim z As Integer = 0
For Each s In ReceiptTextWord1
sb.Append(s.PadRight(spaces1(z)))
z += 1
Next
ElseIf lang = "1" Then
' BL TH : 0610 NO REF. : 1234567890 R.WAHYUDIYONO,IR '
Dim spaces1 = New Integer() {3, 9, 2, 17, 3, 11, 2, 17, 29}
' Now loop on the strings and format them as indicated by the spaces'
' Attention, the value for space include the string itself'
Dim z As Integer = 0
For Each s In ReceiptTextWord1
sb.Append(s.PadRight(spaces1(z)))
z += 1
Next
End If
But right now I should do it on sql.
Right no on my stored procedure, I give the space manually and set in on char variable:
SET #ReceiptText = ' NO REF. : '+#RefNo+' MOHON SIMPAN STRUK INI , SEBAGAI BUKTI PEMBAYARAN YANG SAH '
I thought it's quite annoying, is there any solutions? Or what I've done on vb.net could resolve on sql?
Related
I have a string and I want to get the words in parentheses and list them:
I'm (Kid J)
From (Detroit), (Michigan)
I tried the cod below, but this code only lists two words :
For Each line As String In TextBox1.Lines
Dim i As Integer = line.IndexOf("(")
Dim f As String = line.Substring(i + 1, line.IndexOf(")", i - 1) - i - 1)
TextBox2.AppendText(f + vbCrLf)
Next
the result with this cod is this:
Kid J
Detroit
You can use Regex:
Dim text = "I'm (Kid J)
From (Detroit), (Michigan)"
Dim matches = From match In Regex.Matches(text, "\(([^)]*)\)")
Select match.Groups(1).Value
Console.Write(String.Join(",", matches))
outputs:
Kid J,Detroit,Michigan
Here's the regex with some explanations:
https://regex101.com/r/13ME3n/1
Hoping someone could help me with this. I have the following string:
RSSRRSSRRR;RSRRSSRSRSRSSRSS;RSRSSS;SRRRSSRR;SSSRS;SRSSRRSRRSSS;SRSSRS;SRSSS;RSSRSRSS;RSRSSRSRRSSS;RSSSS;SRSSS;S/RR/SR/SS/RS/RR.SSSRRS;RSSSS;SRSSS;SSSS;RSSRSRSS;SSRSS;SSRRSRSRSS;SRRSRSSS;RSSSRRSS;SSSS;SSSRS;SRSSS;R/SR/SS/RR/RR/SR/RR/S
This is data from a tennis match. The 'S' represents a point won by the server, 'R' represents a point won by the receiver, ';' represents the end of a game and '.' represents the end of the set. The server in the first game will be Player 1 and the server in the second game will be Player 2. This will swap throughout the match after each game. Given a tie break occurs in the 13th game of a set, the '/' will represent when the serve is switched over to the other player.
I want to get the data into the following format:
Set, Game, Point, PlayerPointID, P1net, P2net,result
1, 1, 1, player2 , -1, +1
1, 1, 2, player1 , 0, 0
1, 1, 3, player1 , +1, -1
...
1, 1, 10, player2, -2,+2, Player2
I've wrote the following code so far:
Sub LoopThroughString()
Dim Counter As Integer
Dim MyString As String
MyString = Cells(2, 9)
For Counter = 1 To Len(MyString)
If Mid(MyString, Counter, 1) = "S" Then
Cells(Counter + 1, 16) = Cells(Counter, 16) + 1
ElseIf Mid(MyString, Counter, 1) = "R" Then
Cells(Counter + 1, 16) = Cells(Counter, 16) - 1
End If
Cells(Counter + 1, 17) = -Cells(Counter + 1, 16)
Next
End Sub
That basically just loops the string and calculates net values. I'm not sure however how to deal with the delimiters, how it would swap over player 1 and player 2 after each game. Also how I could do a point, game, set count. The point count would need to reset after each game and the game count would reset after each set. Any ideas?
You can use Split([String], [Delimiter])to get an Array of strings in which there is a delimiter. for example, your string RSSRRSSRRR;RSRRSSRSRSRSSRSS;RSRSSS;SRRRSSRR;SSSRS;SRSSRRSRRSSS;SRSSRS;SRSSS;RSSRSRSS;RSRSSRSRRSSS;RSSSS;SRSSS;S/RR/SR/SS/RS/RR.SSSRRS;RSSSS;SRSSS;SSSS;RSSRSRSS;SSRSS;SSRRSRSRSS;SRRSRSSS;RSSSRRSS;SSSS;SSSRS;SRSSS;R/SR/SS/RR/RR/SR/RR/S when used in the function :
Dim MyArray() As String
MyArray = Split(MyString, ";")
would be separated as such :
RSSRRSSRRR
RSRRSSRSRSRSSRSS
RSRSSS
SRRRSSRR
SSSRS
SRSSRRSRRSSS
SRSSRS
SRSSS
RSSRSRSS
RSRSSRSRRSSS
RSSSS
SRSSS
S/RR/SR/SS/RS/RR.SSSRRS
RSSSS
SRSSS
SSSS
RSSRSRSS
SSRSS
SSRRSRSRSS
SRRSRSSS
RSSSRRSS
SSSS
SSSRS
SRSSS
R/S
R/SS/RR/RR/SR/RR/S
Each line being a separate entry in the Array. MyArray[0] would then be the first line RSSRRSSRRR, which would be the first game, and MyArray[UBound(MyArray)] would be the last one R/SS/RR/RR/SR/RR/S. UBound(MyArray)is the last index of the array provided, which would be equivalent to 25in this example.
To loop through each entry, you can use a for loop :
Dim CurrentGame As Integer
For CurrentGame = 0 to UBound(MyArray)
For Counter = 0 to Len(MyArray[CurrentGame])
' do stuff
' like MyArray[CurrentGame][Counter] to get the character "R", "S" or whatever is there.
Next
Next
NOTE : I assume you are using the default base 0 indexes from your example, but the best practice would be to use For CurrentGame = LBound(MyArray) '... instead, where LBound(MyArray) gives you the first index of the provided Array.
To remember which player is serving, you can create another variable :
Dim player1Serving as Boolean
player1Serving = True
When you want to switch, simply write :
player1Serving = Not player1Serving
And when you want to act according to who is serving :
If player1Serving Then
' Do stuff for Player 1 serving
Else
' Do stuff for Player 2 serving
End If
Using Below codes in VB.net, I have some variables (HUCROW1,HUCROW2,HUCROW3) which are integer type and a specific value is assigned to each of them.
Then in a loop I try to make HUCROW equal to above variables. HUCROW is string type and I concatenate it with the loop number for example by using "HUCROW" & 1.
HUCROW1 = 66
HUCROW2 = 84
HUCROW3 = 102
HUCROW4 = 120
For j = 1 To 3
Dim HUCROW As String = "HUCROW" & (j)
If ScheduleSht.Cells(HUCROW, 9).Value.Ticks <> Nothing Then
HUCdates(i) = ScheduleSht.Cells(HUCROW, 9).value.Ticks
HUCdates(i) = ScheduleSht.Cells(HUCROW, 9).value.Ticks
Else
HUCdates(i) = 0
End If
Next
My aim is to get HUCROW1 value which is 66, but it doesn't work and give "type mismatch error" on ScheduleSht.Cells(HUCROW, 9).value.Ticks as it doesn't convert the string HUCROW to its assigned number.
Any help on how to convert the string type "HUCROW1" to the assigned integer value to HUCROW1 would be appreciated.
I think it's easier to use an array or a dictionary to store and retrive the values.
Array sample (subtract j because an array's index starts from zero)
Dim HUCROWS As Integer() = {66, 84, 102, 120}
For j = 1 To 3
Console.WriteLine(HUCROWS(j - 1))
Next
Dictionary sample
Dim HUCROWS As New Dictionary(Of String, Integer) From {
{"HUCROW1", 66},
{"HUCROW2", 84},
{"HUCROW3", 102},
{"HUCROW4", 120}
}
For j = 1 To 3
Dim HUCROW As String = "HUCROW" & j
Console.WriteLine(HUCROWS(HUCROW))
Next
Result of both codes
66
84
102
Lets say I have a text Howard Johnson, 21 (USA)
I want to get the substring of the text Johnson.
I could do this with InStr and Microsoft.VisualBasic.Left Or Mid, But I always found this method rather tedious and I want to know if there is another easier method to do this.
Dim myText As String = "Howard Johnson, 21 (USA)"
Dim textIWant As String = InStr(1, myText, Chr(32))
Dim LastName As String = Mid(myText, textIWant + 1, textIWant)
'Output: Johnson
Any suggestions?
Try this code - it uses the IndexOf function of a String to locate the first instance of a character within that String.
For a surname, the example code is looking for the first space and the first comma and taking the text in between. The assumption is that the surname is always delimited that way.
For the country, the example code is looking for the first ( and the last ) and taking the text in between. The assumption is that the country is always in round brackets.
Here's the code:
Sub Main()
Dim Input As String
Dim Surname As String
Dim Country As String
Input = "Howard Johnson, 21 (USA)"
Surname = Input.Substring(Input.IndexOf(" ") + 1, Input.IndexOf(",") - Input.IndexOf(" ") - 1)
Country = Input.Substring(Input.IndexOf("(") + 1, Input.IndexOf(")") - Input.IndexOf("(") - 1)
Console.WriteLine(Surname)
Console.WriteLine(Country)
Console.ReadKey()
End Sub
It will also work for people who have spaces in their surname e.g.:
Input = "Albert del Rosario, 75 (Phillipines)"
Surname = Input.Substring(Input.IndexOf(" ") + 1, Input.IndexOf(",") - Input.IndexOf(" ") - 1)
Will output
del Rosario
Dim myText = "Howard Johnson, 21 (USA)"
Dim LastName = myText.Split(" "c, ","c)(1) ' myText.Split(" "c, ","c) gives array {"Howard", "Johnson", "", "21", "(USA)"}
I would like to take the count of character from one position until it reaches a Space Using VBA
Sub testing()
Dim YourText As String
YourText = "my name ismanu prasad"
Cells(1, 1).Value = Len(YourText)
End Sub
Above code will return 21 as output. But my scenario is bit different .I need the count of substring “manu” from the above string and output should be 4
Sub Display4thWord()
Dim Space As String
Dim YourText As String
Dim Begin4thWord As Integer
Dim End4thWord As Integer
YourText = "The first message box display a value"
Space = " "
'Find begin of 4th word.
Begin4thWord = InStr(InStr(InStr(1, YourText, Space, vbBinaryCompare) + 1, YourText, Space, vbBinaryCompare) + 1, YourText, Space, vbBinaryCompare)
'Find end of 4th word/begin of 5th word
End4thWord = InStr(Begin4thWord + 1, YourText, Space, vbBinaryCompare)
MsgBox (Begin4thWord)
'Display 4th word
MsgBox (Mid(YourText, Begin4thWord, End4thWord - Begin4thWord))
End Sub
You need to embed InStr function and use with Mid function.
Is it satisfaction you? This solution have hard code number number of word which it will return.
Declare two variables recordnocount & recordnocount
.position is the value we have
recordnocount = InStr(position + 20, text, " ")
recordnocount1 = recordnocount - (position + 20)
we can get the count .
Thankyou All