|
|
#1 |
|
Member
Join Date: May 07
Posts: 56
![]() |
take text only
HI EVERYBODY
i would like to know if there is a function in vb.net that can take a text without spaces or numbers . ex: dim p as string p=inputbox("give a text please") ' the text for example is "hello " what I want is just "hello" thank you SAAD |
|
|
|
|
|
#2 |
|
Frenzied Member
Join Date: Jun 05
Location: South UK
Posts: 1,653
![]() ![]() ![]() ![]() |
Re: take text only
Trim will remove any leading or trailing spaces.
So NewString = MyString.Trim To remove numbers you would need a small function to loop through the characters and strip any numbers out.
__________________
_________________________________________________________________________________ B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved. |
|
|
|
|
|
#3 |
|
Member
Join Date: May 07
Posts: 56
![]() |
Re: take text only
thank you very much , that what i wa looking for , "it works "
for numbers , in vb.net how to declare a character ? |
|
|
|
|
|
#4 |
|
Frenzied Member
Join Date: Jun 05
Location: South UK
Posts: 1,653
![]() ![]() ![]() ![]() |
Re: take text only
I think this does what you want.
Code:
Option Strict On
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyString As String = "This is my 8 text and it 5 has some 10 numbers in it"
MessageBox.Show(StripNumbersAndDoubleSpaces(MyString.Trim))
End Sub
Private Function StripNumbersAndDoubleSpaces(ByVal instring As String) As String
Dim str As String = String.Empty
Dim PreviousCh As Char = Nothing
For Each ch As Char In instring
If Not Char.IsNumber(ch) Then
If ch = " " Then
If Not PreviousCh = " " Then str += ch
Else
str += ch
End If
PreviousCh = ch
End If
Next
Return str
End Function
End Class
__________________
_________________________________________________________________________________ B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved. |
|
|
|
|
|
#5 |
|
Member
Join Date: May 07
Posts: 56
![]() |
Re: take text only
thank you so much ,dear bulldog you are exact
see you soon |
|
|
|
|
|
#6 |
|
Frenzied Member
Join Date: Jun 05
Location: South UK
Posts: 1,653
![]() ![]() ![]() ![]() |
Re: take text only
Glad to help, assumig your problem is fixed please mark the thread as resolved.
__________________
_________________________________________________________________________________ B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|