473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to only get char from string

24
Hi i have problem with separating Character from string,

e.g:
dim S as string
dim k as string

S="23 * 12 UBV 100";

how to i get output k="UBV"

Its mean only char set if together then i want to put in other variable,

any idea how to I start this.... Thx very much
Mar 18 '08 #1
4 2524
QVeen72
1,445 Expert 1GB
Hi,

Try this if the String Length is fixed..:
k = Mid("23 * 12 UBV 100",9,3)

Regards
Veena
Mar 18 '08 #2
debasisdas
8,127 Expert 4TB
Its mean only char set if together then i want to put in other variable,
If you want only characters then find out all the digits and replace them with space and finally remove space but not the intermediate spaces.
Mar 18 '08 #3
shaif
24
Hi,

Try this if the String Length is fixed..:
k = Mid("23 * 12 UBV 100",9,3)

Regards
Veena
Hi Veena,

Your idea is ok, however, Value of S can be change. I mean I dont know the exactvalue of S, but I know it is including with digit and character, so i want to seperate only characters, Thx again
Mar 18 '08 #4
Killer42
8,435 Expert 8TB
The solution in post #3 should do the job. For example...

Expand|Select|Wrap|Line Numbers
  1. Public Function CharsOnly_V1(ByVal S As String) As String
  2.   Dim I As Long
  3.   For I = 0 To 9
  4.     S = Replace(S, Format$(I), "")
  5.   Next
  6.   CharsOnly_V1 = Trim$(S)
  7. End Function
  8.  
Demo...
Print charsonly_v1(" db dfgjlh 35jkl sekjh 54 4")
db dfgjlh jkl sekjh

Here's another alternative which has the advantage of allowing you more control over which characters are copied and which aren't.

Expand|Select|Wrap|Line Numbers
  1. Public Function CharsOnly_V2(ByVal S As String) As String
  2.   Dim I As Long, Char As String * 1
  3.   For I = 1 To Len(S)
  4.     Char = Mid$(S, I, 1)
  5.     Select Case Char
  6.       Case "0" To "9"
  7.         ' Don't touch.
  8.       Case "a" To "z"
  9.         CharsOnly_V2 = CharsOnly_V2 & Char
  10.       Case "A" To "Z"
  11.         CharsOnly_V2 = CharsOnly_V2 & Char
  12.       Case Else
  13.         ' Don't touch.
  14.     End Select
  15.   Next
  16. End Function
  17.  
Demo...

Print charsonly_v2(" db dfgjlh 35jkl sekjh 54 4")
dbdfgjlhjklsekjh
Mar 19 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: David Gausebeck | last post by:
The inability to denote data members as read-only in C++ is something which has annoyed me (slightly) for a while now. You can always get around it with accessor methods that return const...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
7
by: Nikolay Petrov | last post by:
How to filter out only digits from a string? i.e. fgfdg435fdg7dgf5:df,54 => 4357554 Thanks
17
by: Yogi_Bear_79 | last post by:
I have the following code: sscanf(line, "%d", n_ptr) !=1 || n_ptr <=0; It only partially works. If the user types a character other than 0-9 to start the string it fails. However as long as...
24
by: v4vijayakumar | last post by:
why the following string, 'str' is read-only? char *str = "test string"; anyhow 'str' needs to be in memory. do you think, making 'str' red-only would gain performance? or, it is right?
14
by: YiMkiE | last post by:
I am a newbie of C and I need to do a program to get the current date information only, without the time. I have my code here: #include <stdio.h> #include <time.h> #include <string.h> int...
1
by: marsguy85 | last post by:
Please help me . I am new at C , Learing C will take time but i have to submit this and i dont know how to do it honestly so please help anyone . thanks in advance .I will understand each line of...
7
by: bcpkh | last post by:
Hello All I need to check a string to make sure it does not contain any non numeric characters, the problem that I face is that the string is fairly long, 2784601121574585949, strtol etc. can't...
14
by: dascandy | last post by:
Hi, I was wondering, is it possible to determine whether a string can be modified (const char *) by the application or whether it's located in what's commonly .rodata? Regards, Peter
26
by: karthikbalaguru | last post by:
Hi, While trying to understand the difference between the following 2 methods, i have some interesting queries. Method 1) char *s = "Hello"; and Method 2) char s = "Hello"; How does the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.